OLD | NEW |
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/cast/video_receiver/video_decoder.h" | 5 #include "media/cast/video_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" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/stl_util.h" | |
13 #include "base/values.h" | 12 #include "base/values.h" |
14 #include "media/base/video_util.h" | 13 #include "media/base/video_util.h" |
15 #include "media/cast/cast_defines.h" | 14 #include "media/cast/cast_defines.h" |
16 #include "media/cast/cast_environment.h" | 15 #include "media/cast/cast_environment.h" |
17 // VPX_CODEC_DISABLE_COMPAT excludes parts of the libvpx API that provide | 16 // VPX_CODEC_DISABLE_COMPAT excludes parts of the libvpx API that provide |
18 // backwards compatibility for legacy applications using the library. | 17 // backwards compatibility for legacy applications using the library. |
19 #define VPX_CODEC_DISABLE_COMPAT 1 | 18 #define VPX_CODEC_DISABLE_COMPAT 1 |
20 #include "third_party/libvpx/source/libvpx/vpx/vp8dx.h" | 19 #include "third_party/libvpx/source/libvpx/vpx/vp8dx.h" |
21 #include "third_party/libvpx/source/libvpx/vpx/vpx_decoder.h" | 20 #include "third_party/libvpx/source/libvpx/vpx/vpx_decoder.h" |
22 #include "ui/gfx/size.h" | 21 #include "ui/gfx/size.h" |
(...skipping 11 matching lines...) Expand all Loading... |
34 transport::VideoCodec codec) | 33 transport::VideoCodec codec) |
35 : cast_environment_(cast_environment), | 34 : cast_environment_(cast_environment), |
36 codec_(codec), | 35 codec_(codec), |
37 cast_initialization_status_(STATUS_VIDEO_UNINITIALIZED), | 36 cast_initialization_status_(STATUS_VIDEO_UNINITIALIZED), |
38 seen_first_frame_(false) {} | 37 seen_first_frame_(false) {} |
39 | 38 |
40 CastInitializationStatus InitializationResult() const { | 39 CastInitializationStatus InitializationResult() const { |
41 return cast_initialization_status_; | 40 return cast_initialization_status_; |
42 } | 41 } |
43 | 42 |
44 void DecodeFrame(scoped_ptr<transport::EncodedVideoFrame> encoded_frame, | 43 void DecodeFrame(scoped_ptr<transport::EncodedFrame> encoded_frame, |
45 const DecodeFrameCallback& callback) { | 44 const DecodeFrameCallback& callback) { |
46 DCHECK_EQ(cast_initialization_status_, STATUS_VIDEO_INITIALIZED); | 45 DCHECK_EQ(cast_initialization_status_, STATUS_VIDEO_INITIALIZED); |
47 | 46 |
48 if (encoded_frame->codec != codec_) { | |
49 NOTREACHED(); | |
50 cast_environment_->PostTask( | |
51 CastEnvironment::MAIN, | |
52 FROM_HERE, | |
53 base::Bind(callback, scoped_refptr<VideoFrame>(NULL), false)); | |
54 } | |
55 | |
56 COMPILE_ASSERT(sizeof(encoded_frame->frame_id) == sizeof(last_frame_id_), | 47 COMPILE_ASSERT(sizeof(encoded_frame->frame_id) == sizeof(last_frame_id_), |
57 size_of_frame_id_types_do_not_match); | 48 size_of_frame_id_types_do_not_match); |
58 bool is_continuous = true; | 49 bool is_continuous = true; |
59 if (seen_first_frame_) { | 50 if (seen_first_frame_) { |
60 const uint32 frames_ahead = encoded_frame->frame_id - last_frame_id_; | 51 const uint32 frames_ahead = encoded_frame->frame_id - last_frame_id_; |
61 if (frames_ahead > 1) { | 52 if (frames_ahead > 1) { |
62 RecoverBecauseFramesWereDropped(); | 53 RecoverBecauseFramesWereDropped(); |
63 is_continuous = false; | 54 is_continuous = false; |
64 } | 55 } |
65 } else { | 56 } else { |
66 seen_first_frame_ = true; | 57 seen_first_frame_ = true; |
67 } | 58 } |
68 last_frame_id_ = encoded_frame->frame_id; | 59 last_frame_id_ = encoded_frame->frame_id; |
69 | 60 |
70 const scoped_refptr<VideoFrame> decoded_frame = Decode( | 61 const scoped_refptr<VideoFrame> decoded_frame = Decode( |
71 reinterpret_cast<uint8*>(string_as_array(&encoded_frame->data)), | 62 encoded_frame->mutable_bytes(), |
72 static_cast<int>(encoded_frame->data.size())); | 63 static_cast<int>(encoded_frame->data.size())); |
73 cast_environment_->PostTask( | 64 cast_environment_->PostTask( |
74 CastEnvironment::MAIN, | 65 CastEnvironment::MAIN, |
75 FROM_HERE, | 66 FROM_HERE, |
76 base::Bind(callback, decoded_frame, is_continuous)); | 67 base::Bind(callback, decoded_frame, is_continuous)); |
77 } | 68 } |
78 | 69 |
79 protected: | 70 protected: |
80 friend class base::RefCountedThreadSafe<ImplBase>; | 71 friend class base::RefCountedThreadSafe<ImplBase>; |
81 virtual ~ImplBase() {} | 72 virtual ~ImplBase() {} |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 | 232 |
242 VideoDecoder::~VideoDecoder() {} | 233 VideoDecoder::~VideoDecoder() {} |
243 | 234 |
244 CastInitializationStatus VideoDecoder::InitializationResult() const { | 235 CastInitializationStatus VideoDecoder::InitializationResult() const { |
245 if (impl_) | 236 if (impl_) |
246 return impl_->InitializationResult(); | 237 return impl_->InitializationResult(); |
247 return STATUS_UNSUPPORTED_VIDEO_CODEC; | 238 return STATUS_UNSUPPORTED_VIDEO_CODEC; |
248 } | 239 } |
249 | 240 |
250 void VideoDecoder::DecodeFrame( | 241 void VideoDecoder::DecodeFrame( |
251 scoped_ptr<transport::EncodedVideoFrame> encoded_frame, | 242 scoped_ptr<transport::EncodedFrame> encoded_frame, |
252 const DecodeFrameCallback& callback) { | 243 const DecodeFrameCallback& callback) { |
253 DCHECK(encoded_frame.get()); | 244 DCHECK(encoded_frame.get()); |
254 DCHECK(!callback.is_null()); | 245 DCHECK(!callback.is_null()); |
255 if (!impl_ || impl_->InitializationResult() != STATUS_VIDEO_INITIALIZED) { | 246 if (!impl_ || impl_->InitializationResult() != STATUS_VIDEO_INITIALIZED) { |
256 callback.Run(make_scoped_refptr<VideoFrame>(NULL), false); | 247 callback.Run(make_scoped_refptr<VideoFrame>(NULL), false); |
257 return; | 248 return; |
258 } | 249 } |
259 cast_environment_->PostTask(CastEnvironment::VIDEO, | 250 cast_environment_->PostTask(CastEnvironment::VIDEO, |
260 FROM_HERE, | 251 FROM_HERE, |
261 base::Bind(&VideoDecoder::ImplBase::DecodeFrame, | 252 base::Bind(&VideoDecoder::ImplBase::DecodeFrame, |
262 impl_, | 253 impl_, |
263 base::Passed(&encoded_frame), | 254 base::Passed(&encoded_frame), |
264 callback)); | 255 callback)); |
265 } | 256 } |
266 | 257 |
267 } // namespace cast | 258 } // namespace cast |
268 } // namespace media | 259 } // namespace media |
OLD | NEW |