Partial revert of disabling low latency audio for remote desktop.
[chromium-blink-merge.git] / media / base / video_capture_types.cc
blob1528017456a35c43dde6abe8ee752c2e8a4156d6
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "media/base/video_capture_types.h"
7 #include "base/logging.h"
8 #include "base/strings/stringprintf.h"
9 #include "media/base/limits.h"
11 namespace media {
13 VideoCaptureFormat::VideoCaptureFormat()
14 : frame_rate(0.0f), pixel_format(PIXEL_FORMAT_UNKNOWN) {}
16 VideoCaptureFormat::VideoCaptureFormat(const gfx::Size& frame_size,
17 float frame_rate,
18 VideoPixelFormat pixel_format)
19 : frame_size(frame_size),
20 frame_rate(frame_rate),
21 pixel_format(pixel_format) {}
23 bool VideoCaptureFormat::IsValid() const {
24 return (frame_size.width() < media::limits::kMaxDimension) &&
25 (frame_size.height() < media::limits::kMaxDimension) &&
26 (frame_size.GetArea() >= 0) &&
27 (frame_size.GetArea() < media::limits::kMaxCanvas) &&
28 (frame_rate >= 0.0f) &&
29 (frame_rate < media::limits::kMaxFramesPerSecond) &&
30 (pixel_format >= 0) &&
31 (pixel_format < PIXEL_FORMAT_MAX);
34 size_t VideoCaptureFormat::ImageAllocationSize() const {
35 size_t result_frame_size = frame_size.GetArea();
36 switch (pixel_format) {
37 case PIXEL_FORMAT_I420:
38 case PIXEL_FORMAT_YV12:
39 case PIXEL_FORMAT_NV12:
40 case PIXEL_FORMAT_NV21:
41 result_frame_size = result_frame_size * 3 / 2;
42 break;
43 case PIXEL_FORMAT_UYVY:
44 case PIXEL_FORMAT_YUY2:
45 result_frame_size *= 2;
46 break;
47 case PIXEL_FORMAT_RGB24:
48 result_frame_size *= 3;
49 break;
50 case PIXEL_FORMAT_RGB32:
51 case PIXEL_FORMAT_ARGB:
52 result_frame_size *= 4;
53 break;
54 case PIXEL_FORMAT_MJPEG:
55 case PIXEL_FORMAT_TEXTURE:
56 result_frame_size = 0;
57 break;
58 default: // Sizes for the rest of the formats are unknown.
59 NOTREACHED() << "Unknown pixel format provided.";
60 break;
62 return result_frame_size;
65 std::string VideoCaptureFormat::ToString() const {
66 return base::StringPrintf("resolution: %s, fps: %.3f, pixel format: %s",
67 frame_size.ToString().c_str(),
68 frame_rate,
69 PixelFormatToString(pixel_format).c_str());
72 std::string VideoCaptureFormat::PixelFormatToString(VideoPixelFormat format) {
73 switch (format) {
74 case PIXEL_FORMAT_UNKNOWN:
75 return "UNKNOWN";
76 case PIXEL_FORMAT_I420:
77 return "I420";
78 case PIXEL_FORMAT_YUY2:
79 return "YUY2";
80 case PIXEL_FORMAT_UYVY:
81 return "UYVY";
82 case PIXEL_FORMAT_RGB24:
83 return "RGB24";
84 case PIXEL_FORMAT_RGB32:
85 return "RGB32";
86 case PIXEL_FORMAT_ARGB:
87 return "ARGB";
88 case PIXEL_FORMAT_MJPEG:
89 return "MJPEG";
90 case PIXEL_FORMAT_NV12:
91 return "NV12";
92 case PIXEL_FORMAT_NV21:
93 return "NV21";
94 case PIXEL_FORMAT_YV12:
95 return "YV12";
96 case PIXEL_FORMAT_TEXTURE:
97 return "TEXTURE";
98 case PIXEL_FORMAT_MAX:
99 break;
101 NOTREACHED() << "Invalid VideoPixelFormat provided: " << format;
102 return "";
105 VideoCaptureParams::VideoCaptureParams()
106 : resolution_change_policy(RESOLUTION_POLICY_FIXED) {}
107 } // namespace media