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 #include "media/filters/vpx_video_decoder.h" | 5 #include "media/filters/vpx_video_decoder.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback_helpers.h" | 8 #include "base/callback_helpers.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 const scoped_refptr<DecoderBuffer>& buffer) { | 254 const scoped_refptr<DecoderBuffer>& buffer) { |
255 DCHECK(message_loop_->BelongsToCurrentThread()); | 255 DCHECK(message_loop_->BelongsToCurrentThread()); |
256 DCHECK_NE(state_, kUninitialized); | 256 DCHECK_NE(state_, kUninitialized); |
257 DCHECK_NE(state_, kDecodeFinished); | 257 DCHECK_NE(state_, kDecodeFinished); |
258 DCHECK_NE(state_, kError); | 258 DCHECK_NE(state_, kError); |
259 DCHECK(reset_cb_.is_null()); | 259 DCHECK(reset_cb_.is_null()); |
260 DCHECK(!read_cb_.is_null()); | 260 DCHECK(!read_cb_.is_null()); |
261 DCHECK(buffer.get()); | 261 DCHECK(buffer.get()); |
262 | 262 |
263 // Transition to kDecodeFinished on the first end of stream buffer. | 263 // Transition to kDecodeFinished on the first end of stream buffer. |
264 if (state_ == kNormal && buffer->IsEndOfStream()) { | 264 if (state_ == kNormal && buffer->is_end_of_stream()) { |
265 state_ = kDecodeFinished; | 265 state_ = kDecodeFinished; |
266 base::ResetAndReturn(&read_cb_).Run(kOk, VideoFrame::CreateEmptyFrame()); | 266 base::ResetAndReturn(&read_cb_).Run(kOk, VideoFrame::CreateEmptyFrame()); |
267 return; | 267 return; |
268 } | 268 } |
269 | 269 |
270 scoped_refptr<VideoFrame> video_frame; | 270 scoped_refptr<VideoFrame> video_frame; |
271 if (!Decode(buffer, &video_frame)) { | 271 if (!Decode(buffer, &video_frame)) { |
272 state_ = kError; | 272 state_ = kError; |
273 base::ResetAndReturn(&read_cb_).Run(kDecodeError, NULL); | 273 base::ResetAndReturn(&read_cb_).Run(kDecodeError, NULL); |
274 return; | 274 return; |
275 } | 275 } |
276 | 276 |
277 // Any successful decode counts! | 277 // Any successful decode counts! |
278 if (buffer->GetDataSize() && buffer->GetSideDataSize()) { | 278 if (buffer->get_data_size() && buffer->get_side_data_size()) { |
279 PipelineStatistics statistics; | 279 PipelineStatistics statistics; |
280 statistics.video_bytes_decoded = buffer->GetDataSize(); | 280 statistics.video_bytes_decoded = buffer->get_data_size(); |
281 statistics_cb_.Run(statistics); | 281 statistics_cb_.Run(statistics); |
282 } | 282 } |
283 | 283 |
284 // If we didn't get a frame we need more data. | 284 // If we didn't get a frame we need more data. |
285 if (!video_frame.get()) { | 285 if (!video_frame.get()) { |
286 ReadFromDemuxerStream(); | 286 ReadFromDemuxerStream(); |
287 return; | 287 return; |
288 } | 288 } |
289 | 289 |
290 base::ResetAndReturn(&read_cb_).Run(kOk, video_frame); | 290 base::ResetAndReturn(&read_cb_).Run(kOk, video_frame); |
291 } | 291 } |
292 | 292 |
293 bool VpxVideoDecoder::Decode( | 293 bool VpxVideoDecoder::Decode( |
294 const scoped_refptr<DecoderBuffer>& buffer, | 294 const scoped_refptr<DecoderBuffer>& buffer, |
295 scoped_refptr<VideoFrame>* video_frame) { | 295 scoped_refptr<VideoFrame>* video_frame) { |
296 DCHECK(video_frame); | 296 DCHECK(video_frame); |
297 DCHECK(!buffer->IsEndOfStream()); | 297 DCHECK(!buffer->is_end_of_stream()); |
298 | 298 |
299 // Pass |buffer| to libvpx. | 299 // Pass |buffer| to libvpx. |
300 int64 timestamp = buffer->GetTimestamp().InMicroseconds(); | 300 int64 timestamp = buffer->get_timestamp().InMicroseconds(); |
301 void* user_priv = reinterpret_cast<void*>(×tamp); | 301 void* user_priv = reinterpret_cast<void*>(×tamp); |
302 vpx_codec_err_t status = vpx_codec_decode(vpx_codec_, | 302 vpx_codec_err_t status = vpx_codec_decode(vpx_codec_, |
303 buffer->GetData(), | 303 buffer->get_data(), |
304 buffer->GetDataSize(), | 304 buffer->get_data_size(), |
305 user_priv, | 305 user_priv, |
306 0); | 306 0); |
307 if (status != VPX_CODEC_OK) { | 307 if (status != VPX_CODEC_OK) { |
308 LOG(ERROR) << "vpx_codec_decode() failed, status=" << status; | 308 LOG(ERROR) << "vpx_codec_decode() failed, status=" << status; |
309 return false; | 309 return false; |
310 } | 310 } |
311 | 311 |
312 // Gets pointer to decoded data. | 312 // Gets pointer to decoded data. |
313 vpx_codec_iter_t iter = NULL; | 313 vpx_codec_iter_t iter = NULL; |
314 const vpx_image_t* vpx_image = vpx_codec_get_frame(vpx_codec_, &iter); | 314 const vpx_image_t* vpx_image = vpx_codec_get_frame(vpx_codec_, &iter); |
315 if (!vpx_image) { | 315 if (!vpx_image) { |
316 *video_frame = NULL; | 316 *video_frame = NULL; |
317 return true; | 317 return true; |
318 } | 318 } |
319 | 319 |
320 if (vpx_image->user_priv != reinterpret_cast<void*>(×tamp)) { | 320 if (vpx_image->user_priv != reinterpret_cast<void*>(×tamp)) { |
321 LOG(ERROR) << "Invalid output timestamp."; | 321 LOG(ERROR) << "Invalid output timestamp."; |
322 return false; | 322 return false; |
323 } | 323 } |
324 | 324 |
325 const vpx_image_t* vpx_image_alpha = NULL; | 325 const vpx_image_t* vpx_image_alpha = NULL; |
326 if (vpx_codec_alpha_ && buffer->GetSideDataSize() >= 8) { | 326 if (vpx_codec_alpha_ && buffer->get_side_data_size() >= 8) { |
327 // Pass alpha data to libvpx. | 327 // Pass alpha data to libvpx. |
328 int64 timestamp_alpha = buffer->GetTimestamp().InMicroseconds(); | 328 int64 timestamp_alpha = buffer->get_timestamp().InMicroseconds(); |
329 void* user_priv_alpha = reinterpret_cast<void*>(×tamp_alpha); | 329 void* user_priv_alpha = reinterpret_cast<void*>(×tamp_alpha); |
330 | 330 |
331 // First 8 bytes of side data is side_data_id in big endian. | 331 // First 8 bytes of side data is side_data_id in big endian. |
332 const uint64 side_data_id = base::NetToHost64( | 332 const uint64 side_data_id = base::NetToHost64( |
333 *(reinterpret_cast<const uint64*>(buffer->GetSideData()))); | 333 *(reinterpret_cast<const uint64*>(buffer->get_side_data()))); |
334 if (side_data_id == 1) { | 334 if (side_data_id == 1) { |
335 status = vpx_codec_decode(vpx_codec_alpha_, | 335 status = vpx_codec_decode(vpx_codec_alpha_, |
336 buffer->GetSideData() + 8, | 336 buffer->get_side_data() + 8, |
337 buffer->GetSideDataSize() - 8, | 337 buffer->get_side_data_size() - 8, |
338 user_priv_alpha, | 338 user_priv_alpha, |
339 0); | 339 0); |
340 | 340 |
341 if (status != VPX_CODEC_OK) { | 341 if (status != VPX_CODEC_OK) { |
342 LOG(ERROR) << "vpx_codec_decode() failed on alpha, status=" << status; | 342 LOG(ERROR) << "vpx_codec_decode() failed on alpha, status=" << status; |
343 return false; | 343 return false; |
344 } | 344 } |
345 | 345 |
346 // Gets pointer to decoded data. | 346 // Gets pointer to decoded data. |
347 vpx_codec_iter_t iter_alpha = NULL; | 347 vpx_codec_iter_t iter_alpha = NULL; |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 vpx_image->stride[VPX_PLANE_Y], vpx_image->d_h, video_frame->get()); | 413 vpx_image->stride[VPX_PLANE_Y], vpx_image->d_h, video_frame->get()); |
414 return; | 414 return; |
415 } | 415 } |
416 CopyAPlane(vpx_image_alpha->planes[VPX_PLANE_Y], | 416 CopyAPlane(vpx_image_alpha->planes[VPX_PLANE_Y], |
417 vpx_image->stride[VPX_PLANE_Y], | 417 vpx_image->stride[VPX_PLANE_Y], |
418 vpx_image->d_h, | 418 vpx_image->d_h, |
419 video_frame->get()); | 419 video_frame->get()); |
420 } | 420 } |
421 | 421 |
422 } // namespace media | 422 } // namespace media |
OLD | NEW |