OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 * | 9 * |
10 */ | 10 */ |
(...skipping 339 matching lines...) Loading... |
350 av_buffer_get_opaque(av_frame_->buf[0])); | 350 av_buffer_get_opaque(av_frame_->buf[0])); |
351 RTC_DCHECK(video_frame); | 351 RTC_DCHECK(video_frame); |
352 RTC_CHECK_EQ(av_frame_->data[kYPlaneIndex], | 352 RTC_CHECK_EQ(av_frame_->data[kYPlaneIndex], |
353 video_frame->video_frame_buffer()->DataY()); | 353 video_frame->video_frame_buffer()->DataY()); |
354 RTC_CHECK_EQ(av_frame_->data[kUPlaneIndex], | 354 RTC_CHECK_EQ(av_frame_->data[kUPlaneIndex], |
355 video_frame->video_frame_buffer()->DataU()); | 355 video_frame->video_frame_buffer()->DataU()); |
356 RTC_CHECK_EQ(av_frame_->data[kVPlaneIndex], | 356 RTC_CHECK_EQ(av_frame_->data[kVPlaneIndex], |
357 video_frame->video_frame_buffer()->DataV()); | 357 video_frame->video_frame_buffer()->DataV()); |
358 video_frame->set_timestamp(input_image._timeStamp); | 358 video_frame->set_timestamp(input_image._timeStamp); |
359 | 359 |
360 rtc::Optional<uint8_t> qp; | 360 int32_t ret; |
361 // TODO(sakal): Maybe it is possible to get QP directly from FFmpeg. | |
362 h264_bitstream_parser_.ParseBitstream(input_image._buffer, | |
363 input_image._length); | |
364 int qp_int; | |
365 if (h264_bitstream_parser_.GetLastSliceQp(&qp_int)) { | |
366 qp.emplace(qp_int); | |
367 } | |
368 | 361 |
369 // The decoded image may be larger than what is supposed to be visible, see | 362 // The decoded image may be larger than what is supposed to be visible, see |
370 // |AVGetBuffer2|'s use of |avcodec_align_dimensions|. This crops the image | 363 // |AVGetBuffer2|'s use of |avcodec_align_dimensions|. This crops the image |
371 // without copying the underlying buffer. | 364 // without copying the underlying buffer. |
372 rtc::scoped_refptr<VideoFrameBuffer> buf = video_frame->video_frame_buffer(); | 365 rtc::scoped_refptr<VideoFrameBuffer> buf = video_frame->video_frame_buffer(); |
373 if (av_frame_->width != buf->width() || av_frame_->height != buf->height()) { | 366 if (av_frame_->width != buf->width() || av_frame_->height != buf->height()) { |
374 rtc::scoped_refptr<VideoFrameBuffer> cropped_buf( | 367 rtc::scoped_refptr<VideoFrameBuffer> cropped_buf( |
375 new rtc::RefCountedObject<WrappedI420Buffer>( | 368 new rtc::RefCountedObject<WrappedI420Buffer>( |
376 av_frame_->width, av_frame_->height, | 369 av_frame_->width, av_frame_->height, |
377 buf->DataY(), buf->StrideY(), | 370 buf->DataY(), buf->StrideY(), |
378 buf->DataU(), buf->StrideU(), | 371 buf->DataU(), buf->StrideU(), |
379 buf->DataV(), buf->StrideV(), | 372 buf->DataV(), buf->StrideV(), |
380 rtc::KeepRefUntilDone(buf))); | 373 rtc::KeepRefUntilDone(buf))); |
381 VideoFrame cropped_frame( | 374 VideoFrame cropped_frame( |
382 cropped_buf, video_frame->timestamp(), video_frame->render_time_ms(), | 375 cropped_buf, video_frame->timestamp(), video_frame->render_time_ms(), |
383 video_frame->rotation()); | 376 video_frame->rotation()); |
384 // TODO(nisse): Timestamp and rotation are all zero here. Change decoder | 377 // TODO(nisse): Timestamp and rotation are all zero here. Change decoder |
385 // interface to pass a VideoFrameBuffer instead of a VideoFrame? | 378 // interface to pass a VideoFrameBuffer instead of a VideoFrame? |
386 decoded_image_callback_->Decoded(cropped_frame, rtc::Optional<int32_t>(), | 379 ret = decoded_image_callback_->Decoded(cropped_frame); |
387 qp); | |
388 } else { | 380 } else { |
389 // Return decoded frame. | 381 // Return decoded frame. |
390 decoded_image_callback_->Decoded(*video_frame, rtc::Optional<int32_t>(), | 382 ret = decoded_image_callback_->Decoded(*video_frame); |
391 qp); | |
392 } | 383 } |
393 // Stop referencing it, possibly freeing |video_frame|. | 384 // Stop referencing it, possibly freeing |video_frame|. |
394 av_frame_unref(av_frame_.get()); | 385 av_frame_unref(av_frame_.get()); |
395 video_frame = nullptr; | 386 video_frame = nullptr; |
396 | 387 |
| 388 if (ret) { |
| 389 LOG(LS_WARNING) << "DecodedImageCallback::Decoded returned " << ret; |
| 390 return ret; |
| 391 } |
397 return WEBRTC_VIDEO_CODEC_OK; | 392 return WEBRTC_VIDEO_CODEC_OK; |
398 } | 393 } |
399 | 394 |
400 const char* H264DecoderImpl::ImplementationName() const { | 395 const char* H264DecoderImpl::ImplementationName() const { |
401 return "FFmpeg"; | 396 return "FFmpeg"; |
402 } | 397 } |
403 | 398 |
404 bool H264DecoderImpl::IsInitialized() const { | 399 bool H264DecoderImpl::IsInitialized() const { |
405 return av_context_ != nullptr; | 400 return av_context_ != nullptr; |
406 } | 401 } |
(...skipping 10 matching lines...) Loading... |
417 void H264DecoderImpl::ReportError() { | 412 void H264DecoderImpl::ReportError() { |
418 if (has_reported_error_) | 413 if (has_reported_error_) |
419 return; | 414 return; |
420 RTC_HISTOGRAM_ENUMERATION("WebRTC.Video.H264DecoderImpl.Event", | 415 RTC_HISTOGRAM_ENUMERATION("WebRTC.Video.H264DecoderImpl.Event", |
421 kH264DecoderEventError, | 416 kH264DecoderEventError, |
422 kH264DecoderEventMax); | 417 kH264DecoderEventMax); |
423 has_reported_error_ = true; | 418 has_reported_error_ = true; |
424 } | 419 } |
425 | 420 |
426 } // namespace webrtc | 421 } // namespace webrtc |
OLD | NEW |