OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifndef MEDIA_BASE_VIDEO_FRAME_H_ | 5 #ifndef MEDIA_BASE_VIDEO_FRAME_H_ |
6 #define MEDIA_BASE_VIDEO_FRAME_H_ | 6 #define MEDIA_BASE_VIDEO_FRAME_H_ |
7 | 7 |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/md5.h" | 9 #include "base/md5.h" |
10 #include "media/base/buffers.h" | 10 #include "media/base/buffers.h" |
(...skipping 25 matching lines...) Expand all Loading... |
36 I420 = 11, // 12bpp YVU planar 1x1 Y, 2x2 UV samples. | 36 I420 = 11, // 12bpp YVU planar 1x1 Y, 2x2 UV samples. |
37 NATIVE_TEXTURE = 12, // Native texture. Pixel-format agnostic. | 37 NATIVE_TEXTURE = 12, // Native texture. Pixel-format agnostic. |
38 }; | 38 }; |
39 | 39 |
40 // Creates a new frame in system memory with given parameters. Buffers for | 40 // Creates a new frame in system memory with given parameters. Buffers for |
41 // the frame are allocated but not initialized. | 41 // the frame are allocated but not initialized. |
42 static scoped_refptr<VideoFrame> CreateFrame( | 42 static scoped_refptr<VideoFrame> CreateFrame( |
43 Format format, | 43 Format format, |
44 size_t width, | 44 size_t width, |
45 size_t height, | 45 size_t height, |
46 base::TimeDelta timestamp, | 46 base::TimeDelta timestamp); |
47 base::TimeDelta duration); | |
48 | 47 |
49 // Call prior to CreateFrame to ensure validity of frame configuration. Called | 48 // Call prior to CreateFrame to ensure validity of frame configuration. Called |
50 // automatically by VideoDecoderConfig::IsValidConfig(). | 49 // automatically by VideoDecoderConfig::IsValidConfig(). |
51 // TODO(scherkus): VideoDecoderConfig shouldn't call this method | 50 // TODO(scherkus): VideoDecoderConfig shouldn't call this method |
52 static bool IsValidConfig( | 51 static bool IsValidConfig( |
53 Format format, | 52 Format format, |
54 size_t width, | 53 size_t width, |
55 size_t height); | 54 size_t height); |
56 | 55 |
57 // Wraps a native texture of the given parameters with a VideoFrame. When the | 56 // Wraps a native texture of the given parameters with a VideoFrame. When the |
58 // frame is destroyed |no_longer_needed.Run()| will be called. | 57 // frame is destroyed |no_longer_needed.Run()| will be called. |
59 static scoped_refptr<VideoFrame> WrapNativeTexture( | 58 static scoped_refptr<VideoFrame> WrapNativeTexture( |
60 uint32 texture_id, | 59 uint32 texture_id, |
61 uint32 texture_target, | 60 uint32 texture_target, |
62 size_t width, | 61 size_t width, |
63 size_t height, | 62 size_t height, |
64 base::TimeDelta timestamp, | 63 base::TimeDelta timestamp, |
65 base::TimeDelta duration, | |
66 const base::Closure& no_longer_needed); | 64 const base::Closure& no_longer_needed); |
67 | 65 |
68 // Creates a frame with format equals to VideoFrame::EMPTY, width, height | 66 // Creates a frame with format equals to VideoFrame::EMPTY, width, height, |
69 // timestamp and duration are all 0. | 67 // and timestamp are all 0. |
70 static scoped_refptr<VideoFrame> CreateEmptyFrame(); | 68 static scoped_refptr<VideoFrame> CreateEmptyFrame(); |
71 | 69 |
72 // Allocates YV12 frame based on |width| and |height|, and sets its data to | 70 // Allocates YV12 frame based on |width| and |height|, and sets its data to |
73 // the YUV equivalent of RGB(0,0,0). | 71 // the YUV equivalent of RGB(0,0,0). |
74 static scoped_refptr<VideoFrame> CreateBlackFrame(int width, int height); | 72 static scoped_refptr<VideoFrame> CreateBlackFrame(int width, int height); |
75 | 73 |
76 Format format() const { return format_; } | 74 Format format() const { return format_; } |
77 | 75 |
78 size_t width() const { return width_; } | 76 size_t width() const { return width_; } |
79 | 77 |
(...skipping 22 matching lines...) Expand all Loading... |
102 // Returns true if this VideoFrame represents the end of the stream. | 100 // Returns true if this VideoFrame represents the end of the stream. |
103 bool IsEndOfStream() const; | 101 bool IsEndOfStream() const; |
104 | 102 |
105 base::TimeDelta GetTimestamp() const { | 103 base::TimeDelta GetTimestamp() const { |
106 return timestamp_; | 104 return timestamp_; |
107 } | 105 } |
108 void SetTimestamp(const base::TimeDelta& timestamp) { | 106 void SetTimestamp(const base::TimeDelta& timestamp) { |
109 timestamp_ = timestamp; | 107 timestamp_ = timestamp; |
110 } | 108 } |
111 | 109 |
112 base::TimeDelta GetDuration() const { | |
113 return duration_; | |
114 } | |
115 void SetDuration(const base::TimeDelta& duration) { | |
116 duration_ = duration; | |
117 } | |
118 | |
119 // Used to keep a running hash of seen frames. Expects an initialized MD5 | 110 // Used to keep a running hash of seen frames. Expects an initialized MD5 |
120 // context. Calls MD5Update with the context and the contents of the frame. | 111 // context. Calls MD5Update with the context and the contents of the frame. |
121 void HashFrameForTesting(base::MD5Context* context); | 112 void HashFrameForTesting(base::MD5Context* context); |
122 | 113 |
123 private: | 114 private: |
124 friend class base::RefCountedThreadSafe<VideoFrame>; | 115 friend class base::RefCountedThreadSafe<VideoFrame>; |
125 // Clients must use the static CreateFrame() method to create a new frame. | 116 // Clients must use the static CreateFrame() method to create a new frame. |
126 VideoFrame(Format format, | 117 VideoFrame(Format format, |
127 size_t video_width, | 118 size_t video_width, |
128 size_t video_height, | 119 size_t video_height, |
129 base::TimeDelta timestamp, | 120 base::TimeDelta timestamp); |
130 base::TimeDelta duration); | |
131 virtual ~VideoFrame(); | 121 virtual ~VideoFrame(); |
132 | 122 |
133 // Used internally by CreateFrame(). | 123 // Used internally by CreateFrame(). |
134 void AllocateRGB(size_t bytes_per_pixel); | 124 void AllocateRGB(size_t bytes_per_pixel); |
135 void AllocateYUV(); | 125 void AllocateYUV(); |
136 | 126 |
137 // Used to DCHECK() plane parameters. | 127 // Used to DCHECK() plane parameters. |
138 bool IsValidPlane(size_t plane) const; | 128 bool IsValidPlane(size_t plane) const; |
139 | 129 |
140 // Frame format. | 130 // Frame format. |
(...skipping 10 matching lines...) Expand all Loading... |
151 | 141 |
152 // Array of data pointers to each plane. | 142 // Array of data pointers to each plane. |
153 uint8* data_[kMaxPlanes]; | 143 uint8* data_[kMaxPlanes]; |
154 | 144 |
155 // Native texture ID, if this is a NATIVE_TEXTURE frame. | 145 // Native texture ID, if this is a NATIVE_TEXTURE frame. |
156 uint32 texture_id_; | 146 uint32 texture_id_; |
157 uint32 texture_target_; | 147 uint32 texture_target_; |
158 base::Closure texture_no_longer_needed_; | 148 base::Closure texture_no_longer_needed_; |
159 | 149 |
160 base::TimeDelta timestamp_; | 150 base::TimeDelta timestamp_; |
161 base::TimeDelta duration_; | |
162 | 151 |
163 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoFrame); | 152 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoFrame); |
164 }; | 153 }; |
165 | 154 |
166 } // namespace media | 155 } // namespace media |
167 | 156 |
168 #endif // MEDIA_BASE_VIDEO_FRAME_H_ | 157 #endif // MEDIA_BASE_VIDEO_FRAME_H_ |
OLD | NEW |