Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(112)

Side by Side Diff: media/base/video_capture_types.cc

Issue 1204063005: Reland: Video Capture: extract storage info from pixel format in VideoCaptureFormat. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: dcheng@ nit on DCHECK_EQ(expected, actual) Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/base/video_capture_types.h ('k') | media/capture/screen_capture_device_core.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "media/base/video_capture_types.h" 5 #include "media/base/video_capture_types.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/strings/stringprintf.h" 8 #include "base/strings/stringprintf.h"
9 #include "media/base/limits.h" 9 #include "media/base/limits.h"
10 10
11 namespace media { 11 namespace media {
12 12
13 VideoCaptureFormat::VideoCaptureFormat() 13 VideoCaptureFormat::VideoCaptureFormat()
14 : frame_rate(0.0f), pixel_format(PIXEL_FORMAT_UNKNOWN) {} 14 : frame_rate(0.0f),
15 pixel_format(PIXEL_FORMAT_UNKNOWN),
16 pixel_storage(PIXEL_STORAGE_CPU) {
17 }
15 18
16 VideoCaptureFormat::VideoCaptureFormat(const gfx::Size& frame_size, 19 VideoCaptureFormat::VideoCaptureFormat(const gfx::Size& frame_size,
17 float frame_rate, 20 float frame_rate,
18 VideoPixelFormat pixel_format) 21 VideoPixelFormat pixel_format)
19 : frame_size(frame_size), 22 : frame_size(frame_size),
20 frame_rate(frame_rate), 23 frame_rate(frame_rate),
21 pixel_format(pixel_format) {} 24 pixel_format(pixel_format),
25 pixel_storage(PIXEL_STORAGE_CPU) {
26 }
27
28 VideoCaptureFormat::VideoCaptureFormat(const gfx::Size& frame_size,
29 float frame_rate,
30 VideoPixelFormat pixel_format,
31 VideoPixelStorage pixel_storage)
32 : frame_size(frame_size),
33 frame_rate(frame_rate),
34 pixel_format(pixel_format),
35 pixel_storage(pixel_storage) {
36 }
22 37
23 bool VideoCaptureFormat::IsValid() const { 38 bool VideoCaptureFormat::IsValid() const {
24 return (frame_size.width() < media::limits::kMaxDimension) && 39 return (frame_size.width() < media::limits::kMaxDimension) &&
25 (frame_size.height() < media::limits::kMaxDimension) && 40 (frame_size.height() < media::limits::kMaxDimension) &&
26 (frame_size.GetArea() >= 0) && 41 (frame_size.GetArea() >= 0) &&
27 (frame_size.GetArea() < media::limits::kMaxCanvas) && 42 (frame_size.GetArea() < media::limits::kMaxCanvas) &&
28 (frame_rate >= 0.0f) && 43 (frame_rate >= 0.0f) &&
29 (frame_rate < media::limits::kMaxFramesPerSecond) && 44 (frame_rate < media::limits::kMaxFramesPerSecond) &&
30 (pixel_format >= 0) && 45 (pixel_format >= 0) && (pixel_format < PIXEL_FORMAT_MAX) &&
31 (pixel_format < PIXEL_FORMAT_MAX); 46 (pixel_storage != PIXEL_STORAGE_TEXTURE ||
47 pixel_format == PIXEL_FORMAT_ARGB);
32 } 48 }
33 49
34 size_t VideoCaptureFormat::ImageAllocationSize() const { 50 size_t VideoCaptureFormat::ImageAllocationSize() const {
35 size_t result_frame_size = frame_size.GetArea(); 51 size_t result_frame_size = frame_size.GetArea();
36 switch (pixel_format) { 52 switch (pixel_format) {
37 case PIXEL_FORMAT_I420: 53 case PIXEL_FORMAT_I420:
38 case PIXEL_FORMAT_YV12: 54 case PIXEL_FORMAT_YV12:
39 case PIXEL_FORMAT_NV12: 55 case PIXEL_FORMAT_NV12:
40 case PIXEL_FORMAT_NV21: 56 case PIXEL_FORMAT_NV21:
41 result_frame_size = result_frame_size * 3 / 2; 57 result_frame_size = result_frame_size * 3 / 2;
42 break; 58 break;
43 case PIXEL_FORMAT_UYVY: 59 case PIXEL_FORMAT_UYVY:
44 case PIXEL_FORMAT_YUY2: 60 case PIXEL_FORMAT_YUY2:
45 result_frame_size *= 2; 61 result_frame_size *= 2;
46 break; 62 break;
47 case PIXEL_FORMAT_RGB24: 63 case PIXEL_FORMAT_RGB24:
48 result_frame_size *= 3; 64 result_frame_size *= 3;
49 break; 65 break;
50 case PIXEL_FORMAT_RGB32: 66 case PIXEL_FORMAT_RGB32:
51 case PIXEL_FORMAT_ARGB: 67 case PIXEL_FORMAT_ARGB:
52 // GpuMemoryBuffer is an endianness-agnostic 32bpp pixel format until
53 // http://crbug.com/439520 is closed.
54 case PIXEL_FORMAT_GPUMEMORYBUFFER:
55 result_frame_size *= 4; 68 result_frame_size *= 4;
56 break; 69 break;
57 case PIXEL_FORMAT_MJPEG: 70 case PIXEL_FORMAT_MJPEG:
58 case PIXEL_FORMAT_TEXTURE:
59 result_frame_size = 0; 71 result_frame_size = 0;
60 break; 72 break;
61 default: // Sizes for the rest of the formats are unknown. 73 default: // Sizes for the rest of the formats are unknown.
62 NOTREACHED() << "Unknown pixel format provided."; 74 NOTREACHED() << "Unknown pixel format provided.";
63 break; 75 break;
64 } 76 }
65 return result_frame_size; 77 return result_frame_size;
66 } 78 }
67 79
68 std::string VideoCaptureFormat::ToString() const { 80 std::string VideoCaptureFormat::ToString() const {
69 return base::StringPrintf("resolution: %s, fps: %.3f, pixel format: %s", 81 return base::StringPrintf("(%s)@%.3ffps, pixel format: %s storage: %s.",
70 frame_size.ToString().c_str(), 82 frame_size.ToString().c_str(), frame_rate,
71 frame_rate, 83 PixelFormatToString(pixel_format).c_str(),
72 PixelFormatToString(pixel_format).c_str()); 84 PixelStorageToString(pixel_storage).c_str());
73 } 85 }
74 86
87 //static
75 std::string VideoCaptureFormat::PixelFormatToString(VideoPixelFormat format) { 88 std::string VideoCaptureFormat::PixelFormatToString(VideoPixelFormat format) {
76 switch (format) { 89 switch (format) {
77 case PIXEL_FORMAT_UNKNOWN: 90 case PIXEL_FORMAT_UNKNOWN:
78 return "UNKNOWN"; 91 return "UNKNOWN";
79 case PIXEL_FORMAT_I420: 92 case PIXEL_FORMAT_I420:
80 return "I420"; 93 return "I420";
81 case PIXEL_FORMAT_YUY2: 94 case PIXEL_FORMAT_YUY2:
82 return "YUY2"; 95 return "YUY2";
83 case PIXEL_FORMAT_UYVY: 96 case PIXEL_FORMAT_UYVY:
84 return "UYVY"; 97 return "UYVY";
85 case PIXEL_FORMAT_RGB24: 98 case PIXEL_FORMAT_RGB24:
86 return "RGB24"; 99 return "RGB24";
87 case PIXEL_FORMAT_RGB32: 100 case PIXEL_FORMAT_RGB32:
88 return "RGB32"; 101 return "RGB32";
89 case PIXEL_FORMAT_ARGB: 102 case PIXEL_FORMAT_ARGB:
90 return "ARGB"; 103 return "ARGB";
91 case PIXEL_FORMAT_MJPEG: 104 case PIXEL_FORMAT_MJPEG:
92 return "MJPEG"; 105 return "MJPEG";
93 case PIXEL_FORMAT_NV12: 106 case PIXEL_FORMAT_NV12:
94 return "NV12"; 107 return "NV12";
95 case PIXEL_FORMAT_NV21: 108 case PIXEL_FORMAT_NV21:
96 return "NV21"; 109 return "NV21";
97 case PIXEL_FORMAT_YV12: 110 case PIXEL_FORMAT_YV12:
98 return "YV12"; 111 return "YV12";
99 case PIXEL_FORMAT_TEXTURE: 112 case PIXEL_FORMAT_MAX:
100 return "TEXTURE"; 113 break;
101 case PIXEL_FORMAT_GPUMEMORYBUFFER:
102 return "GPUMEMORYBUFFER";
103 case PIXEL_FORMAT_MAX:
104 break;
105 } 114 }
106 NOTREACHED() << "Invalid VideoPixelFormat provided: " << format; 115 NOTREACHED() << "Invalid VideoPixelFormat provided: " << format;
107 return ""; 116 return std::string();
117 }
118
119 //static
120 std::string VideoCaptureFormat::PixelStorageToString(
121 VideoPixelStorage storage) {
122 switch (storage) {
123 case PIXEL_STORAGE_CPU:
124 return "CPU";
125 case PIXEL_STORAGE_TEXTURE:
126 return "TEXTURE";
127 case PIXEL_STORAGE_GPUMEMORYBUFFER:
128 return "GPUMEMORYBUFFER";
129 }
130 NOTREACHED() << "Invalid VideoPixelStorage provided: "
131 << static_cast<int>(storage);
132 return std::string();
108 } 133 }
109 134
110 VideoCaptureParams::VideoCaptureParams() 135 VideoCaptureParams::VideoCaptureParams()
111 : resolution_change_policy(RESOLUTION_POLICY_FIXED_RESOLUTION) 136 : resolution_change_policy(RESOLUTION_POLICY_FIXED_RESOLUTION)
112 #if defined(OS_LINUX) 137 #if defined(OS_LINUX)
113 , use_native_gpu_memory_buffers(false) 138 , use_native_gpu_memory_buffers(false)
114 #endif 139 #endif
115 {} 140 {}
116 141
117 } // namespace media 142 } // namespace media
OLDNEW
« no previous file with comments | « media/base/video_capture_types.h ('k') | media/capture/screen_capture_device_core.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698