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

Side by Side Diff: media/cast/receiver/video_decoder.cc

Issue 388663003: Cast: Reshuffle files under media/cast (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: missing includes Created 6 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 | Annotate | Revision Log
« no previous file with comments | « media/cast/receiver/video_decoder.h ('k') | media/cast/receiver/video_decoder_unittest.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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/cast/receiver/video_decoder.h" 5 #include "media/cast/receiver/video_decoder.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/json/json_reader.h" 9 #include "base/json/json_reader.h"
10 #include "base/location.h" 10 #include "base/location.h"
(...skipping 12 matching lines...) Expand all
23 namespace media { 23 namespace media {
24 namespace cast { 24 namespace cast {
25 25
26 // Base class that handles the common problem of detecting dropped frames, and 26 // Base class that handles the common problem of detecting dropped frames, and
27 // then invoking the Decode() method implemented by the subclasses to convert 27 // then invoking the Decode() method implemented by the subclasses to convert
28 // the encoded payload data into a usable video frame. 28 // the encoded payload data into a usable video frame.
29 class VideoDecoder::ImplBase 29 class VideoDecoder::ImplBase
30 : public base::RefCountedThreadSafe<VideoDecoder::ImplBase> { 30 : public base::RefCountedThreadSafe<VideoDecoder::ImplBase> {
31 public: 31 public:
32 ImplBase(const scoped_refptr<CastEnvironment>& cast_environment, 32 ImplBase(const scoped_refptr<CastEnvironment>& cast_environment,
33 transport::Codec codec) 33 Codec codec)
34 : cast_environment_(cast_environment), 34 : cast_environment_(cast_environment),
35 codec_(codec), 35 codec_(codec),
36 cast_initialization_status_(STATUS_VIDEO_UNINITIALIZED), 36 cast_initialization_status_(STATUS_VIDEO_UNINITIALIZED),
37 seen_first_frame_(false) {} 37 seen_first_frame_(false) {}
38 38
39 CastInitializationStatus InitializationResult() const { 39 CastInitializationStatus InitializationResult() const {
40 return cast_initialization_status_; 40 return cast_initialization_status_;
41 } 41 }
42 42
43 void DecodeFrame(scoped_ptr<transport::EncodedFrame> encoded_frame, 43 void DecodeFrame(scoped_ptr<EncodedFrame> encoded_frame,
44 const DecodeFrameCallback& callback) { 44 const DecodeFrameCallback& callback) {
45 DCHECK_EQ(cast_initialization_status_, STATUS_VIDEO_INITIALIZED); 45 DCHECK_EQ(cast_initialization_status_, STATUS_VIDEO_INITIALIZED);
46 46
47 COMPILE_ASSERT(sizeof(encoded_frame->frame_id) == sizeof(last_frame_id_), 47 COMPILE_ASSERT(sizeof(encoded_frame->frame_id) == sizeof(last_frame_id_),
48 size_of_frame_id_types_do_not_match); 48 size_of_frame_id_types_do_not_match);
49 bool is_continuous = true; 49 bool is_continuous = true;
50 if (seen_first_frame_) { 50 if (seen_first_frame_) {
51 const uint32 frames_ahead = encoded_frame->frame_id - last_frame_id_; 51 const uint32 frames_ahead = encoded_frame->frame_id - last_frame_id_;
52 if (frames_ahead > 1) { 52 if (frames_ahead > 1) {
53 RecoverBecauseFramesWereDropped(); 53 RecoverBecauseFramesWereDropped();
(...skipping 16 matching lines...) Expand all
70 protected: 70 protected:
71 friend class base::RefCountedThreadSafe<ImplBase>; 71 friend class base::RefCountedThreadSafe<ImplBase>;
72 virtual ~ImplBase() {} 72 virtual ~ImplBase() {}
73 73
74 virtual void RecoverBecauseFramesWereDropped() {} 74 virtual void RecoverBecauseFramesWereDropped() {}
75 75
76 // Note: Implementation of Decode() is allowed to mutate |data|. 76 // Note: Implementation of Decode() is allowed to mutate |data|.
77 virtual scoped_refptr<VideoFrame> Decode(uint8* data, int len) = 0; 77 virtual scoped_refptr<VideoFrame> Decode(uint8* data, int len) = 0;
78 78
79 const scoped_refptr<CastEnvironment> cast_environment_; 79 const scoped_refptr<CastEnvironment> cast_environment_;
80 const transport::Codec codec_; 80 const Codec codec_;
81 81
82 // Subclass' ctor is expected to set this to STATUS_VIDEO_INITIALIZED. 82 // Subclass' ctor is expected to set this to STATUS_VIDEO_INITIALIZED.
83 CastInitializationStatus cast_initialization_status_; 83 CastInitializationStatus cast_initialization_status_;
84 84
85 private: 85 private:
86 bool seen_first_frame_; 86 bool seen_first_frame_;
87 uint32 last_frame_id_; 87 uint32 last_frame_id_;
88 88
89 DISALLOW_COPY_AND_ASSIGN(ImplBase); 89 DISALLOW_COPY_AND_ASSIGN(ImplBase);
90 }; 90 };
91 91
92 class VideoDecoder::Vp8Impl : public VideoDecoder::ImplBase { 92 class VideoDecoder::Vp8Impl : public VideoDecoder::ImplBase {
93 public: 93 public:
94 explicit Vp8Impl(const scoped_refptr<CastEnvironment>& cast_environment) 94 explicit Vp8Impl(const scoped_refptr<CastEnvironment>& cast_environment)
95 : ImplBase(cast_environment, transport::CODEC_VIDEO_VP8) { 95 : ImplBase(cast_environment, CODEC_VIDEO_VP8) {
96 if (ImplBase::cast_initialization_status_ != STATUS_VIDEO_UNINITIALIZED) 96 if (ImplBase::cast_initialization_status_ != STATUS_VIDEO_UNINITIALIZED)
97 return; 97 return;
98 98
99 vpx_codec_dec_cfg_t cfg = {0}; 99 vpx_codec_dec_cfg_t cfg = {0};
100 // TODO(miu): Revisit this for typical multi-core desktop use case. This 100 // TODO(miu): Revisit this for typical multi-core desktop use case. This
101 // feels like it should be 4 or 8. 101 // feels like it should be 4 or 8.
102 cfg.threads = 1; 102 cfg.threads = 1;
103 103
104 DCHECK(vpx_codec_get_caps(vpx_codec_vp8_dx()) & VPX_CODEC_CAP_POSTPROC); 104 DCHECK(vpx_codec_get_caps(vpx_codec_vp8_dx()) & VPX_CODEC_CAP_POSTPROC);
105 if (vpx_codec_dec_init(&context_, 105 if (vpx_codec_dec_init(&context_,
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 vpx_codec_ctx_t context_; 166 vpx_codec_ctx_t context_;
167 167
168 DISALLOW_COPY_AND_ASSIGN(Vp8Impl); 168 DISALLOW_COPY_AND_ASSIGN(Vp8Impl);
169 }; 169 };
170 170
171 #ifndef OFFICIAL_BUILD 171 #ifndef OFFICIAL_BUILD
172 // A fake video decoder that always output 2x2 black frames. 172 // A fake video decoder that always output 2x2 black frames.
173 class VideoDecoder::FakeImpl : public VideoDecoder::ImplBase { 173 class VideoDecoder::FakeImpl : public VideoDecoder::ImplBase {
174 public: 174 public:
175 explicit FakeImpl(const scoped_refptr<CastEnvironment>& cast_environment) 175 explicit FakeImpl(const scoped_refptr<CastEnvironment>& cast_environment)
176 : ImplBase(cast_environment, transport::CODEC_VIDEO_FAKE), 176 : ImplBase(cast_environment, CODEC_VIDEO_FAKE),
177 last_decoded_id_(-1) { 177 last_decoded_id_(-1) {
178 if (ImplBase::cast_initialization_status_ != STATUS_VIDEO_UNINITIALIZED) 178 if (ImplBase::cast_initialization_status_ != STATUS_VIDEO_UNINITIALIZED)
179 return; 179 return;
180 ImplBase::cast_initialization_status_ = STATUS_VIDEO_INITIALIZED; 180 ImplBase::cast_initialization_status_ = STATUS_VIDEO_INITIALIZED;
181 } 181 }
182 182
183 private: 183 private:
184 virtual ~FakeImpl() {} 184 virtual ~FakeImpl() {}
185 185
186 virtual scoped_refptr<VideoFrame> Decode(uint8* data, int len) OVERRIDE { 186 virtual scoped_refptr<VideoFrame> Decode(uint8* data, int len) OVERRIDE {
(...skipping 20 matching lines...) Expand all
207 } 207 }
208 208
209 int last_decoded_id_; 209 int last_decoded_id_;
210 210
211 DISALLOW_COPY_AND_ASSIGN(FakeImpl); 211 DISALLOW_COPY_AND_ASSIGN(FakeImpl);
212 }; 212 };
213 #endif 213 #endif
214 214
215 VideoDecoder::VideoDecoder( 215 VideoDecoder::VideoDecoder(
216 const scoped_refptr<CastEnvironment>& cast_environment, 216 const scoped_refptr<CastEnvironment>& cast_environment,
217 transport::Codec codec) 217 Codec codec)
218 : cast_environment_(cast_environment) { 218 : cast_environment_(cast_environment) {
219 switch (codec) { 219 switch (codec) {
220 #ifndef OFFICIAL_BUILD 220 #ifndef OFFICIAL_BUILD
221 case transport::CODEC_VIDEO_FAKE: 221 case CODEC_VIDEO_FAKE:
222 impl_ = new FakeImpl(cast_environment); 222 impl_ = new FakeImpl(cast_environment);
223 break; 223 break;
224 #endif 224 #endif
225 case transport::CODEC_VIDEO_VP8: 225 case CODEC_VIDEO_VP8:
226 impl_ = new Vp8Impl(cast_environment); 226 impl_ = new Vp8Impl(cast_environment);
227 break; 227 break;
228 case transport::CODEC_VIDEO_H264: 228 case CODEC_VIDEO_H264:
229 // TODO(miu): Need implementation. 229 // TODO(miu): Need implementation.
230 NOTIMPLEMENTED(); 230 NOTIMPLEMENTED();
231 break; 231 break;
232 default: 232 default:
233 NOTREACHED() << "Unknown or unspecified codec."; 233 NOTREACHED() << "Unknown or unspecified codec.";
234 break; 234 break;
235 } 235 }
236 } 236 }
237 237
238 VideoDecoder::~VideoDecoder() {} 238 VideoDecoder::~VideoDecoder() {}
239 239
240 CastInitializationStatus VideoDecoder::InitializationResult() const { 240 CastInitializationStatus VideoDecoder::InitializationResult() const {
241 if (impl_) 241 if (impl_)
242 return impl_->InitializationResult(); 242 return impl_->InitializationResult();
243 return STATUS_UNSUPPORTED_VIDEO_CODEC; 243 return STATUS_UNSUPPORTED_VIDEO_CODEC;
244 } 244 }
245 245
246 void VideoDecoder::DecodeFrame( 246 void VideoDecoder::DecodeFrame(
247 scoped_ptr<transport::EncodedFrame> encoded_frame, 247 scoped_ptr<EncodedFrame> encoded_frame,
248 const DecodeFrameCallback& callback) { 248 const DecodeFrameCallback& callback) {
249 DCHECK(encoded_frame.get()); 249 DCHECK(encoded_frame.get());
250 DCHECK(!callback.is_null()); 250 DCHECK(!callback.is_null());
251 if (!impl_ || impl_->InitializationResult() != STATUS_VIDEO_INITIALIZED) { 251 if (!impl_ || impl_->InitializationResult() != STATUS_VIDEO_INITIALIZED) {
252 callback.Run(make_scoped_refptr<VideoFrame>(NULL), false); 252 callback.Run(make_scoped_refptr<VideoFrame>(NULL), false);
253 return; 253 return;
254 } 254 }
255 cast_environment_->PostTask(CastEnvironment::VIDEO, 255 cast_environment_->PostTask(CastEnvironment::VIDEO,
256 FROM_HERE, 256 FROM_HERE,
257 base::Bind(&VideoDecoder::ImplBase::DecodeFrame, 257 base::Bind(&VideoDecoder::ImplBase::DecodeFrame,
258 impl_, 258 impl_,
259 base::Passed(&encoded_frame), 259 base::Passed(&encoded_frame),
260 callback)); 260 callback));
261 } 261 }
262 262
263 } // namespace cast 263 } // namespace cast
264 } // namespace media 264 } // namespace media
OLDNEW
« no previous file with comments | « media/cast/receiver/video_decoder.h ('k') | media/cast/receiver/video_decoder_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698