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 "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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 } | 42 } |
43 | 43 |
44 void DecodeFrame(scoped_ptr<EncodedFrame> encoded_frame, | 44 void DecodeFrame(scoped_ptr<EncodedFrame> encoded_frame, |
45 const DecodeFrameCallback& callback) { | 45 const DecodeFrameCallback& callback) { |
46 DCHECK_EQ(operational_status_, STATUS_INITIALIZED); | 46 DCHECK_EQ(operational_status_, STATUS_INITIALIZED); |
47 | 47 |
48 static_assert(sizeof(encoded_frame->frame_id) == sizeof(last_frame_id_), | 48 static_assert(sizeof(encoded_frame->frame_id) == sizeof(last_frame_id_), |
49 "size of frame_id types do not match"); | 49 "size of frame_id types do not match"); |
50 bool is_continuous = true; | 50 bool is_continuous = true; |
51 if (seen_first_frame_) { | 51 if (seen_first_frame_) { |
52 const uint32 frames_ahead = encoded_frame->frame_id - last_frame_id_; | 52 const uint32_t frames_ahead = encoded_frame->frame_id - last_frame_id_; |
53 if (frames_ahead > 1) { | 53 if (frames_ahead > 1) { |
54 RecoverBecauseFramesWereDropped(); | 54 RecoverBecauseFramesWereDropped(); |
55 is_continuous = false; | 55 is_continuous = false; |
56 } | 56 } |
57 } else { | 57 } else { |
58 seen_first_frame_ = true; | 58 seen_first_frame_ = true; |
59 } | 59 } |
60 last_frame_id_ = encoded_frame->frame_id; | 60 last_frame_id_ = encoded_frame->frame_id; |
61 | 61 |
62 const scoped_refptr<VideoFrame> decoded_frame = Decode( | 62 const scoped_refptr<VideoFrame> decoded_frame = Decode( |
(...skipping 14 matching lines...) Expand all Loading... |
77 base::Bind(callback, decoded_frame, is_continuous)); | 77 base::Bind(callback, decoded_frame, is_continuous)); |
78 } | 78 } |
79 | 79 |
80 protected: | 80 protected: |
81 friend class base::RefCountedThreadSafe<ImplBase>; | 81 friend class base::RefCountedThreadSafe<ImplBase>; |
82 virtual ~ImplBase() {} | 82 virtual ~ImplBase() {} |
83 | 83 |
84 virtual void RecoverBecauseFramesWereDropped() {} | 84 virtual void RecoverBecauseFramesWereDropped() {} |
85 | 85 |
86 // Note: Implementation of Decode() is allowed to mutate |data|. | 86 // Note: Implementation of Decode() is allowed to mutate |data|. |
87 virtual scoped_refptr<VideoFrame> Decode(uint8* data, int len) = 0; | 87 virtual scoped_refptr<VideoFrame> Decode(uint8_t* data, int len) = 0; |
88 | 88 |
89 const scoped_refptr<CastEnvironment> cast_environment_; | 89 const scoped_refptr<CastEnvironment> cast_environment_; |
90 const Codec codec_; | 90 const Codec codec_; |
91 | 91 |
92 // Subclass' ctor is expected to set this to STATUS_INITIALIZED. | 92 // Subclass' ctor is expected to set this to STATUS_INITIALIZED. |
93 OperationalStatus operational_status_; | 93 OperationalStatus operational_status_; |
94 | 94 |
95 // Pool of VideoFrames to decode incoming frames into. | 95 // Pool of VideoFrames to decode incoming frames into. |
96 media::VideoFramePool video_frame_pool_; | 96 media::VideoFramePool video_frame_pool_; |
97 | 97 |
98 private: | 98 private: |
99 bool seen_first_frame_; | 99 bool seen_first_frame_; |
100 uint32 last_frame_id_; | 100 uint32_t last_frame_id_; |
101 | 101 |
102 DISALLOW_COPY_AND_ASSIGN(ImplBase); | 102 DISALLOW_COPY_AND_ASSIGN(ImplBase); |
103 }; | 103 }; |
104 | 104 |
105 class VideoDecoder::Vp8Impl : public VideoDecoder::ImplBase { | 105 class VideoDecoder::Vp8Impl : public VideoDecoder::ImplBase { |
106 public: | 106 public: |
107 explicit Vp8Impl(const scoped_refptr<CastEnvironment>& cast_environment) | 107 explicit Vp8Impl(const scoped_refptr<CastEnvironment>& cast_environment) |
108 : ImplBase(cast_environment, CODEC_VIDEO_VP8) { | 108 : ImplBase(cast_environment, CODEC_VIDEO_VP8) { |
109 if (ImplBase::operational_status_ != STATUS_UNINITIALIZED) | 109 if (ImplBase::operational_status_ != STATUS_UNINITIALIZED) |
110 return; | 110 return; |
(...skipping 13 matching lines...) Expand all Loading... |
124 } | 124 } |
125 ImplBase::operational_status_ = STATUS_INITIALIZED; | 125 ImplBase::operational_status_ = STATUS_INITIALIZED; |
126 } | 126 } |
127 | 127 |
128 private: | 128 private: |
129 ~Vp8Impl() final { | 129 ~Vp8Impl() final { |
130 if (ImplBase::operational_status_ == STATUS_INITIALIZED) | 130 if (ImplBase::operational_status_ == STATUS_INITIALIZED) |
131 CHECK_EQ(VPX_CODEC_OK, vpx_codec_destroy(&context_)); | 131 CHECK_EQ(VPX_CODEC_OK, vpx_codec_destroy(&context_)); |
132 } | 132 } |
133 | 133 |
134 scoped_refptr<VideoFrame> Decode(uint8* data, int len) final { | 134 scoped_refptr<VideoFrame> Decode(uint8_t* data, int len) final { |
135 if (len <= 0 || vpx_codec_decode(&context_, | 135 if (len <= 0 || vpx_codec_decode(&context_, |
136 data, | 136 data, |
137 static_cast<unsigned int>(len), | 137 static_cast<unsigned int>(len), |
138 NULL, | 138 NULL, |
139 0) != VPX_CODEC_OK) { | 139 0) != VPX_CODEC_OK) { |
140 return NULL; | 140 return NULL; |
141 } | 141 } |
142 | 142 |
143 vpx_codec_iter_t iter = NULL; | 143 vpx_codec_iter_t iter = NULL; |
144 vpx_image_t* const image = vpx_codec_get_frame(&context_, &iter); | 144 vpx_image_t* const image = vpx_codec_get_frame(&context_, &iter); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 : ImplBase(cast_environment, CODEC_VIDEO_FAKE), | 186 : ImplBase(cast_environment, CODEC_VIDEO_FAKE), |
187 last_decoded_id_(-1) { | 187 last_decoded_id_(-1) { |
188 if (ImplBase::operational_status_ != STATUS_UNINITIALIZED) | 188 if (ImplBase::operational_status_ != STATUS_UNINITIALIZED) |
189 return; | 189 return; |
190 ImplBase::operational_status_ = STATUS_INITIALIZED; | 190 ImplBase::operational_status_ = STATUS_INITIALIZED; |
191 } | 191 } |
192 | 192 |
193 private: | 193 private: |
194 ~FakeImpl() final {} | 194 ~FakeImpl() final {} |
195 | 195 |
196 scoped_refptr<VideoFrame> Decode(uint8* data, int len) final { | 196 scoped_refptr<VideoFrame> Decode(uint8_t* data, int len) final { |
197 // Make sure this is a JSON string. | 197 // Make sure this is a JSON string. |
198 if (!len || data[0] != '{') | 198 if (!len || data[0] != '{') |
199 return NULL; | 199 return NULL; |
200 base::JSONReader reader; | 200 base::JSONReader reader; |
201 scoped_ptr<base::Value> values( | 201 scoped_ptr<base::Value> values( |
202 reader.Read(base::StringPiece(reinterpret_cast<char*>(data), len))); | 202 reader.Read(base::StringPiece(reinterpret_cast<char*>(data), len))); |
203 if (!values) | 203 if (!values) |
204 return NULL; | 204 return NULL; |
205 base::DictionaryValue* dict = NULL; | 205 base::DictionaryValue* dict = NULL; |
206 values->GetAsDictionary(&dict); | 206 values->GetAsDictionary(&dict); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 cast_environment_->PostTask(CastEnvironment::VIDEO, | 265 cast_environment_->PostTask(CastEnvironment::VIDEO, |
266 FROM_HERE, | 266 FROM_HERE, |
267 base::Bind(&VideoDecoder::ImplBase::DecodeFrame, | 267 base::Bind(&VideoDecoder::ImplBase::DecodeFrame, |
268 impl_, | 268 impl_, |
269 base::Passed(&encoded_frame), | 269 base::Passed(&encoded_frame), |
270 callback)); | 270 callback)); |
271 } | 271 } |
272 | 272 |
273 } // namespace cast | 273 } // namespace cast |
274 } // namespace media | 274 } // namespace media |
OLD | NEW |