OLD | NEW |
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 <stdint.h> | 7 #include <stdint.h> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 27 matching lines...) Expand all Loading... |
38 Codec codec) | 38 Codec codec) |
39 : cast_environment_(cast_environment), | 39 : cast_environment_(cast_environment), |
40 codec_(codec), | 40 codec_(codec), |
41 operational_status_(STATUS_UNINITIALIZED), | 41 operational_status_(STATUS_UNINITIALIZED), |
42 seen_first_frame_(false) {} | 42 seen_first_frame_(false) {} |
43 | 43 |
44 OperationalStatus InitializationResult() const { | 44 OperationalStatus InitializationResult() const { |
45 return operational_status_; | 45 return operational_status_; |
46 } | 46 } |
47 | 47 |
48 void DecodeFrame(scoped_ptr<EncodedFrame> encoded_frame, | 48 void DecodeFrame(std::unique_ptr<EncodedFrame> encoded_frame, |
49 const DecodeFrameCallback& callback) { | 49 const DecodeFrameCallback& callback) { |
50 DCHECK_EQ(operational_status_, STATUS_INITIALIZED); | 50 DCHECK_EQ(operational_status_, STATUS_INITIALIZED); |
51 | 51 |
52 static_assert(sizeof(encoded_frame->frame_id) == sizeof(last_frame_id_), | 52 static_assert(sizeof(encoded_frame->frame_id) == sizeof(last_frame_id_), |
53 "size of frame_id types do not match"); | 53 "size of frame_id types do not match"); |
54 bool is_continuous = true; | 54 bool is_continuous = true; |
55 if (seen_first_frame_) { | 55 if (seen_first_frame_) { |
56 const uint32_t frames_ahead = encoded_frame->frame_id - last_frame_id_; | 56 const uint32_t frames_ahead = encoded_frame->frame_id - last_frame_id_; |
57 if (frames_ahead > 1) { | 57 if (frames_ahead > 1) { |
58 RecoverBecauseFramesWereDropped(); | 58 RecoverBecauseFramesWereDropped(); |
59 is_continuous = false; | 59 is_continuous = false; |
60 } | 60 } |
61 } else { | 61 } else { |
62 seen_first_frame_ = true; | 62 seen_first_frame_ = true; |
63 } | 63 } |
64 last_frame_id_ = encoded_frame->frame_id; | 64 last_frame_id_ = encoded_frame->frame_id; |
65 | 65 |
66 const scoped_refptr<VideoFrame> decoded_frame = Decode( | 66 const scoped_refptr<VideoFrame> decoded_frame = Decode( |
67 encoded_frame->mutable_bytes(), | 67 encoded_frame->mutable_bytes(), |
68 static_cast<int>(encoded_frame->data.size())); | 68 static_cast<int>(encoded_frame->data.size())); |
69 decoded_frame->set_timestamp( | 69 decoded_frame->set_timestamp( |
70 encoded_frame->rtp_timestamp.ToTimeDelta(kVideoFrequency)); | 70 encoded_frame->rtp_timestamp.ToTimeDelta(kVideoFrequency)); |
71 | 71 |
72 scoped_ptr<FrameEvent> decode_event(new FrameEvent()); | 72 std::unique_ptr<FrameEvent> decode_event(new FrameEvent()); |
73 decode_event->timestamp = cast_environment_->Clock()->NowTicks(); | 73 decode_event->timestamp = cast_environment_->Clock()->NowTicks(); |
74 decode_event->type = FRAME_DECODED; | 74 decode_event->type = FRAME_DECODED; |
75 decode_event->media_type = VIDEO_EVENT; | 75 decode_event->media_type = VIDEO_EVENT; |
76 decode_event->rtp_timestamp = encoded_frame->rtp_timestamp; | 76 decode_event->rtp_timestamp = encoded_frame->rtp_timestamp; |
77 decode_event->frame_id = encoded_frame->frame_id; | 77 decode_event->frame_id = encoded_frame->frame_id; |
78 cast_environment_->logger()->DispatchFrameEvent(std::move(decode_event)); | 78 cast_environment_->logger()->DispatchFrameEvent(std::move(decode_event)); |
79 | 79 |
80 cast_environment_->PostTask( | 80 cast_environment_->PostTask( |
81 CastEnvironment::MAIN, | 81 CastEnvironment::MAIN, |
82 FROM_HERE, | 82 FROM_HERE, |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 } | 197 } |
198 | 198 |
199 private: | 199 private: |
200 ~FakeImpl() final {} | 200 ~FakeImpl() final {} |
201 | 201 |
202 scoped_refptr<VideoFrame> Decode(uint8_t* data, int len) final { | 202 scoped_refptr<VideoFrame> Decode(uint8_t* data, int len) final { |
203 // Make sure this is a JSON string. | 203 // Make sure this is a JSON string. |
204 if (!len || data[0] != '{') | 204 if (!len || data[0] != '{') |
205 return NULL; | 205 return NULL; |
206 base::JSONReader reader; | 206 base::JSONReader reader; |
207 scoped_ptr<base::Value> values( | 207 std::unique_ptr<base::Value> values( |
208 reader.Read(base::StringPiece(reinterpret_cast<char*>(data), len))); | 208 reader.Read(base::StringPiece(reinterpret_cast<char*>(data), len))); |
209 if (!values) | 209 if (!values) |
210 return NULL; | 210 return NULL; |
211 base::DictionaryValue* dict = NULL; | 211 base::DictionaryValue* dict = NULL; |
212 values->GetAsDictionary(&dict); | 212 values->GetAsDictionary(&dict); |
213 | 213 |
214 bool key = false; | 214 bool key = false; |
215 int id = 0; | 215 int id = 0; |
216 int ref = 0; | 216 int ref = 0; |
217 dict->GetBoolean("key", &key); | 217 dict->GetBoolean("key", &key); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 } | 252 } |
253 | 253 |
254 VideoDecoder::~VideoDecoder() {} | 254 VideoDecoder::~VideoDecoder() {} |
255 | 255 |
256 OperationalStatus VideoDecoder::InitializationResult() const { | 256 OperationalStatus VideoDecoder::InitializationResult() const { |
257 if (impl_.get()) | 257 if (impl_.get()) |
258 return impl_->InitializationResult(); | 258 return impl_->InitializationResult(); |
259 return STATUS_UNSUPPORTED_CODEC; | 259 return STATUS_UNSUPPORTED_CODEC; |
260 } | 260 } |
261 | 261 |
262 void VideoDecoder::DecodeFrame( | 262 void VideoDecoder::DecodeFrame(std::unique_ptr<EncodedFrame> encoded_frame, |
263 scoped_ptr<EncodedFrame> encoded_frame, | 263 const DecodeFrameCallback& callback) { |
264 const DecodeFrameCallback& callback) { | |
265 DCHECK(encoded_frame.get()); | 264 DCHECK(encoded_frame.get()); |
266 DCHECK(!callback.is_null()); | 265 DCHECK(!callback.is_null()); |
267 if (!impl_.get() || impl_->InitializationResult() != STATUS_INITIALIZED) { | 266 if (!impl_.get() || impl_->InitializationResult() != STATUS_INITIALIZED) { |
268 callback.Run(make_scoped_refptr<VideoFrame>(NULL), false); | 267 callback.Run(make_scoped_refptr<VideoFrame>(NULL), false); |
269 return; | 268 return; |
270 } | 269 } |
271 cast_environment_->PostTask(CastEnvironment::VIDEO, | 270 cast_environment_->PostTask(CastEnvironment::VIDEO, |
272 FROM_HERE, | 271 FROM_HERE, |
273 base::Bind(&VideoDecoder::ImplBase::DecodeFrame, | 272 base::Bind(&VideoDecoder::ImplBase::DecodeFrame, |
274 impl_, | 273 impl_, |
275 base::Passed(&encoded_frame), | 274 base::Passed(&encoded_frame), |
276 callback)); | 275 callback)); |
277 } | 276 } |
278 | 277 |
279 } // namespace cast | 278 } // namespace cast |
280 } // namespace media | 279 } // namespace media |
OLD | NEW |