| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2014 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 896 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 907 // In practice libvpx keeps a few (~3-4) buffers alive at a time. | 907 // In practice libvpx keeps a few (~3-4) buffers alive at a time. |
| 908 if (vpx_codec_decode(decoder_, buffer, | 908 if (vpx_codec_decode(decoder_, buffer, |
| 909 static_cast<unsigned int>(input_image._length), 0, | 909 static_cast<unsigned int>(input_image._length), 0, |
| 910 VPX_DL_REALTIME)) { | 910 VPX_DL_REALTIME)) { |
| 911 return WEBRTC_VIDEO_CODEC_ERROR; | 911 return WEBRTC_VIDEO_CODEC_ERROR; |
| 912 } | 912 } |
| 913 // |img->fb_priv| contains the image data, a reference counted Vp9FrameBuffer. | 913 // |img->fb_priv| contains the image data, a reference counted Vp9FrameBuffer. |
| 914 // It may be released by libvpx during future vpx_codec_decode or | 914 // It may be released by libvpx during future vpx_codec_decode or |
| 915 // vpx_codec_destroy calls. | 915 // vpx_codec_destroy calls. |
| 916 img = vpx_codec_get_frame(decoder_, &iter); | 916 img = vpx_codec_get_frame(decoder_, &iter); |
| 917 int ret = ReturnFrame(img, input_image._timeStamp, input_image.ntp_time_ms_); | 917 int ret = ReturnFrame(img, input_image._timeStamp); |
| 918 if (ret != 0) { | 918 if (ret != 0) { |
| 919 return ret; | 919 return ret; |
| 920 } | 920 } |
| 921 return WEBRTC_VIDEO_CODEC_OK; | 921 return WEBRTC_VIDEO_CODEC_OK; |
| 922 } | 922 } |
| 923 | 923 |
| 924 int VP9DecoderImpl::ReturnFrame(const vpx_image_t* img, | 924 int VP9DecoderImpl::ReturnFrame(const vpx_image_t* img, uint32_t timestamp) { |
| 925 uint32_t timestamp, | |
| 926 int64_t ntp_time_ms) { | |
| 927 if (img == NULL) { | 925 if (img == NULL) { |
| 928 // Decoder OK and NULL image => No show frame. | 926 // Decoder OK and NULL image => No show frame. |
| 929 return WEBRTC_VIDEO_CODEC_NO_OUTPUT; | 927 return WEBRTC_VIDEO_CODEC_NO_OUTPUT; |
| 930 } | 928 } |
| 931 | 929 |
| 932 // This buffer contains all of |img|'s image data, a reference counted | 930 // This buffer contains all of |img|'s image data, a reference counted |
| 933 // Vp9FrameBuffer. (libvpx is done with the buffers after a few | 931 // Vp9FrameBuffer. (libvpx is done with the buffers after a few |
| 934 // vpx_codec_decode calls or vpx_codec_destroy). | 932 // vpx_codec_decode calls or vpx_codec_destroy). |
| 935 Vp9FrameBufferPool::Vp9FrameBuffer* img_buffer = | 933 Vp9FrameBufferPool::Vp9FrameBuffer* img_buffer = |
| 936 static_cast<Vp9FrameBufferPool::Vp9FrameBuffer*>(img->fb_priv); | 934 static_cast<Vp9FrameBufferPool::Vp9FrameBuffer*>(img->fb_priv); |
| 937 // The buffer can be used directly by the VideoFrame (without copy) by | 935 // The buffer can be used directly by the VideoFrame (without copy) by |
| 938 // using a WrappedI420Buffer. | 936 // using a WrappedI420Buffer. |
| 939 rtc::scoped_refptr<WrappedI420Buffer> img_wrapped_buffer( | 937 rtc::scoped_refptr<WrappedI420Buffer> img_wrapped_buffer( |
| 940 new rtc::RefCountedObject<webrtc::WrappedI420Buffer>( | 938 new rtc::RefCountedObject<webrtc::WrappedI420Buffer>( |
| 941 img->d_w, img->d_h, img->planes[VPX_PLANE_Y], | 939 img->d_w, img->d_h, img->planes[VPX_PLANE_Y], |
| 942 img->stride[VPX_PLANE_Y], img->planes[VPX_PLANE_U], | 940 img->stride[VPX_PLANE_Y], img->planes[VPX_PLANE_U], |
| 943 img->stride[VPX_PLANE_U], img->planes[VPX_PLANE_V], | 941 img->stride[VPX_PLANE_U], img->planes[VPX_PLANE_V], |
| 944 img->stride[VPX_PLANE_V], | 942 img->stride[VPX_PLANE_V], |
| 945 // WrappedI420Buffer's mechanism for allowing the release of its frame | 943 // WrappedI420Buffer's mechanism for allowing the release of its frame |
| 946 // buffer is through a callback function. This is where we should | 944 // buffer is through a callback function. This is where we should |
| 947 // release |img_buffer|. | 945 // release |img_buffer|. |
| 948 rtc::KeepRefUntilDone(img_buffer))); | 946 rtc::KeepRefUntilDone(img_buffer))); |
| 949 | 947 |
| 950 VideoFrame decoded_image; | 948 VideoFrame decoded_image; |
| 951 decoded_image.set_video_frame_buffer(img_wrapped_buffer); | 949 decoded_image.set_video_frame_buffer(img_wrapped_buffer); |
| 952 decoded_image.set_timestamp(timestamp); | 950 decoded_image.set_timestamp(timestamp); |
| 953 decoded_image.set_ntp_time_ms(ntp_time_ms); | |
| 954 int ret = decode_complete_callback_->Decoded(decoded_image); | 951 int ret = decode_complete_callback_->Decoded(decoded_image); |
| 955 if (ret != 0) | 952 if (ret != 0) |
| 956 return ret; | 953 return ret; |
| 957 return WEBRTC_VIDEO_CODEC_OK; | 954 return WEBRTC_VIDEO_CODEC_OK; |
| 958 } | 955 } |
| 959 | 956 |
| 960 int VP9DecoderImpl::RegisterDecodeCompleteCallback( | 957 int VP9DecoderImpl::RegisterDecodeCompleteCallback( |
| 961 DecodedImageCallback* callback) { | 958 DecodedImageCallback* callback) { |
| 962 decode_complete_callback_ = callback; | 959 decode_complete_callback_ = callback; |
| 963 return WEBRTC_VIDEO_CODEC_OK; | 960 return WEBRTC_VIDEO_CODEC_OK; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 979 frame_buffer_pool_.ClearPool(); | 976 frame_buffer_pool_.ClearPool(); |
| 980 inited_ = false; | 977 inited_ = false; |
| 981 return WEBRTC_VIDEO_CODEC_OK; | 978 return WEBRTC_VIDEO_CODEC_OK; |
| 982 } | 979 } |
| 983 | 980 |
| 984 const char* VP9DecoderImpl::ImplementationName() const { | 981 const char* VP9DecoderImpl::ImplementationName() const { |
| 985 return "libvpx"; | 982 return "libvpx"; |
| 986 } | 983 } |
| 987 | 984 |
| 988 } // namespace webrtc | 985 } // namespace webrtc |
| OLD | NEW |