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...) Expand 10 before | Expand all | Expand 10 after 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 int32_t ret; | 360 rtc::Optional<uint8_t> qp; |
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 = rtc::Optional<uint8_t>(qp_int); | |
sprang_webrtc
2017/02/28 09:01:52
nit: qp.emplace(qp_int);
sakal
2017/03/01 13:26:48
Done.
| |
367 } | |
361 | 368 |
362 // The decoded image may be larger than what is supposed to be visible, see | 369 // The decoded image may be larger than what is supposed to be visible, see |
363 // |AVGetBuffer2|'s use of |avcodec_align_dimensions|. This crops the image | 370 // |AVGetBuffer2|'s use of |avcodec_align_dimensions|. This crops the image |
364 // without copying the underlying buffer. | 371 // without copying the underlying buffer. |
365 rtc::scoped_refptr<VideoFrameBuffer> buf = video_frame->video_frame_buffer(); | 372 rtc::scoped_refptr<VideoFrameBuffer> buf = video_frame->video_frame_buffer(); |
366 if (av_frame_->width != buf->width() || av_frame_->height != buf->height()) { | 373 if (av_frame_->width != buf->width() || av_frame_->height != buf->height()) { |
367 rtc::scoped_refptr<VideoFrameBuffer> cropped_buf( | 374 rtc::scoped_refptr<VideoFrameBuffer> cropped_buf( |
368 new rtc::RefCountedObject<WrappedI420Buffer>( | 375 new rtc::RefCountedObject<WrappedI420Buffer>( |
369 av_frame_->width, av_frame_->height, | 376 av_frame_->width, av_frame_->height, |
370 buf->DataY(), buf->StrideY(), | 377 buf->DataY(), buf->StrideY(), |
371 buf->DataU(), buf->StrideU(), | 378 buf->DataU(), buf->StrideU(), |
372 buf->DataV(), buf->StrideV(), | 379 buf->DataV(), buf->StrideV(), |
373 rtc::KeepRefUntilDone(buf))); | 380 rtc::KeepRefUntilDone(buf))); |
374 VideoFrame cropped_frame( | 381 VideoFrame cropped_frame( |
375 cropped_buf, video_frame->timestamp(), video_frame->render_time_ms(), | 382 cropped_buf, video_frame->timestamp(), video_frame->render_time_ms(), |
376 video_frame->rotation()); | 383 video_frame->rotation()); |
377 // TODO(nisse): Timestamp and rotation are all zero here. Change decoder | 384 // TODO(nisse): Timestamp and rotation are all zero here. Change decoder |
378 // interface to pass a VideoFrameBuffer instead of a VideoFrame? | 385 // interface to pass a VideoFrameBuffer instead of a VideoFrame? |
379 ret = decoded_image_callback_->Decoded(cropped_frame); | 386 decoded_image_callback_->Decoded(cropped_frame, rtc::Optional<int32_t>(), |
387 qp); | |
380 } else { | 388 } else { |
381 // Return decoded frame. | 389 // Return decoded frame. |
382 ret = decoded_image_callback_->Decoded(*video_frame); | 390 decoded_image_callback_->Decoded(*video_frame, rtc::Optional<int32_t>(), |
391 qp); | |
383 } | 392 } |
384 // Stop referencing it, possibly freeing |video_frame|. | 393 // Stop referencing it, possibly freeing |video_frame|. |
385 av_frame_unref(av_frame_.get()); | 394 av_frame_unref(av_frame_.get()); |
386 video_frame = nullptr; | 395 video_frame = nullptr; |
387 | 396 |
388 if (ret) { | |
389 LOG(LS_WARNING) << "DecodedImageCallback::Decoded returned " << ret; | |
390 return ret; | |
391 } | |
392 return WEBRTC_VIDEO_CODEC_OK; | 397 return WEBRTC_VIDEO_CODEC_OK; |
393 } | 398 } |
394 | 399 |
395 const char* H264DecoderImpl::ImplementationName() const { | 400 const char* H264DecoderImpl::ImplementationName() const { |
396 return "FFmpeg"; | 401 return "FFmpeg"; |
397 } | 402 } |
398 | 403 |
399 bool H264DecoderImpl::IsInitialized() const { | 404 bool H264DecoderImpl::IsInitialized() const { |
400 return av_context_ != nullptr; | 405 return av_context_ != nullptr; |
401 } | 406 } |
(...skipping 10 matching lines...) Expand all Loading... | |
412 void H264DecoderImpl::ReportError() { | 417 void H264DecoderImpl::ReportError() { |
413 if (has_reported_error_) | 418 if (has_reported_error_) |
414 return; | 419 return; |
415 RTC_HISTOGRAM_ENUMERATION("WebRTC.Video.H264DecoderImpl.Event", | 420 RTC_HISTOGRAM_ENUMERATION("WebRTC.Video.H264DecoderImpl.Event", |
416 kH264DecoderEventError, | 421 kH264DecoderEventError, |
417 kH264DecoderEventMax); | 422 kH264DecoderEventMax); |
418 has_reported_error_ = true; | 423 has_reported_error_ = true; |
419 } | 424 } |
420 | 425 |
421 } // namespace webrtc | 426 } // namespace webrtc |
OLD | NEW |