| 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 */ |
| 11 | 11 |
| 12 #include "webrtc/modules/video_coding/codecs/vp9/vp9_impl.h" | 12 #include "webrtc/modules/video_coding/codecs/vp9/vp9_impl.h" |
| 13 | 13 |
| 14 #include <stdlib.h> | 14 #include <stdlib.h> |
| 15 #include <string.h> | 15 #include <string.h> |
| 16 #include <time.h> | 16 #include <time.h> |
| 17 #include <vector> | 17 #include <vector> |
| 18 | 18 |
| 19 #include "vpx/vpx_encoder.h" | 19 #include "vpx/vpx_encoder.h" |
| 20 #include "vpx/vpx_decoder.h" | 20 #include "vpx/vpx_decoder.h" |
| 21 #include "vpx/vp8cx.h" | 21 #include "vpx/vp8cx.h" |
| 22 #include "vpx/vp8dx.h" | 22 #include "vpx/vp8dx.h" |
| 23 | 23 |
| 24 #include "webrtc/base/bind.h" | |
| 25 #include "webrtc/base/checks.h" | 24 #include "webrtc/base/checks.h" |
| 25 #include "webrtc/base/keep_ref_until_done.h" |
| 26 #include "webrtc/base/logging.h" | 26 #include "webrtc/base/logging.h" |
| 27 #include "webrtc/base/trace_event.h" | 27 #include "webrtc/base/trace_event.h" |
| 28 #include "webrtc/common.h" | 28 #include "webrtc/common.h" |
| 29 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" | 29 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" |
| 30 #include "webrtc/modules/include/module_common_types.h" | 30 #include "webrtc/modules/include/module_common_types.h" |
| 31 #include "webrtc/modules/video_coding/codecs/vp9/screenshare_layers.h" | 31 #include "webrtc/modules/video_coding/codecs/vp9/screenshare_layers.h" |
| 32 #include "webrtc/system_wrappers/include/tick_util.h" | 32 #include "webrtc/system_wrappers/include/tick_util.h" |
| 33 | 33 |
| 34 namespace { | |
| 35 | |
| 36 // VP9DecoderImpl::ReturnFrame helper function used with WrappedI420Buffer. | |
| 37 static void WrappedI420BufferNoLongerUsedCb( | |
| 38 webrtc::Vp9FrameBufferPool::Vp9FrameBuffer* img_buffer) { | |
| 39 img_buffer->Release(); | |
| 40 } | |
| 41 | |
| 42 } // anonymous namespace | |
| 43 | |
| 44 namespace webrtc { | 34 namespace webrtc { |
| 45 | 35 |
| 46 // Only positive speeds, range for real-time coding currently is: 5 - 8. | 36 // Only positive speeds, range for real-time coding currently is: 5 - 8. |
| 47 // Lower means slower/better quality, higher means fastest/lower quality. | 37 // Lower means slower/better quality, higher means fastest/lower quality. |
| 48 int GetCpuSpeed(int width, int height) { | 38 int GetCpuSpeed(int width, int height) { |
| 49 // For smaller resolutions, use lower speed setting (get some coding gain at | 39 // For smaller resolutions, use lower speed setting (get some coding gain at |
| 50 // the cost of increased encoding complexity). | 40 // the cost of increased encoding complexity). |
| 51 if (width * height <= 352 * 288) | 41 if (width * height <= 352 * 288) |
| 52 return 5; | 42 return 5; |
| 53 else | 43 else |
| (...skipping 872 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 926 return WEBRTC_VIDEO_CODEC_OK; | 916 return WEBRTC_VIDEO_CODEC_OK; |
| 927 } | 917 } |
| 928 | 918 |
| 929 int VP9DecoderImpl::ReturnFrame(const vpx_image_t* img, uint32_t timestamp) { | 919 int VP9DecoderImpl::ReturnFrame(const vpx_image_t* img, uint32_t timestamp) { |
| 930 if (img == NULL) { | 920 if (img == NULL) { |
| 931 // Decoder OK and NULL image => No show frame. | 921 // Decoder OK and NULL image => No show frame. |
| 932 return WEBRTC_VIDEO_CODEC_NO_OUTPUT; | 922 return WEBRTC_VIDEO_CODEC_NO_OUTPUT; |
| 933 } | 923 } |
| 934 | 924 |
| 935 // This buffer contains all of |img|'s image data, a reference counted | 925 // This buffer contains all of |img|'s image data, a reference counted |
| 936 // Vp9FrameBuffer. Performing AddRef/Release ensures it is not released and | 926 // Vp9FrameBuffer. (libvpx is done with the buffers after a few |
| 937 // recycled during use (libvpx is done with the buffers after a few | |
| 938 // vpx_codec_decode calls or vpx_codec_destroy). | 927 // vpx_codec_decode calls or vpx_codec_destroy). |
| 939 Vp9FrameBufferPool::Vp9FrameBuffer* img_buffer = | 928 Vp9FrameBufferPool::Vp9FrameBuffer* img_buffer = |
| 940 static_cast<Vp9FrameBufferPool::Vp9FrameBuffer*>(img->fb_priv); | 929 static_cast<Vp9FrameBufferPool::Vp9FrameBuffer*>(img->fb_priv); |
| 941 img_buffer->AddRef(); | |
| 942 // The buffer can be used directly by the VideoFrame (without copy) by | 930 // The buffer can be used directly by the VideoFrame (without copy) by |
| 943 // using a WrappedI420Buffer. | 931 // using a WrappedI420Buffer. |
| 944 rtc::scoped_refptr<WrappedI420Buffer> img_wrapped_buffer( | 932 rtc::scoped_refptr<WrappedI420Buffer> img_wrapped_buffer( |
| 945 new rtc::RefCountedObject<webrtc::WrappedI420Buffer>( | 933 new rtc::RefCountedObject<webrtc::WrappedI420Buffer>( |
| 946 img->d_w, img->d_h, | 934 img->d_w, img->d_h, |
| 947 img->planes[VPX_PLANE_Y], img->stride[VPX_PLANE_Y], | 935 img->planes[VPX_PLANE_Y], img->stride[VPX_PLANE_Y], |
| 948 img->planes[VPX_PLANE_U], img->stride[VPX_PLANE_U], | 936 img->planes[VPX_PLANE_U], img->stride[VPX_PLANE_U], |
| 949 img->planes[VPX_PLANE_V], img->stride[VPX_PLANE_V], | 937 img->planes[VPX_PLANE_V], img->stride[VPX_PLANE_V], |
| 950 // WrappedI420Buffer's mechanism for allowing the release of its frame | 938 // WrappedI420Buffer's mechanism for allowing the release of its frame |
| 951 // buffer is through a callback function. This is where we should | 939 // buffer is through a callback function. This is where we should |
| 952 // release |img_buffer|. | 940 // release |img_buffer|. |
| 953 rtc::Bind(&WrappedI420BufferNoLongerUsedCb, img_buffer))); | 941 rtc::KeepRefUntilDone(img_buffer))); |
| 954 | 942 |
| 955 VideoFrame decoded_image; | 943 VideoFrame decoded_image; |
| 956 decoded_image.set_video_frame_buffer(img_wrapped_buffer); | 944 decoded_image.set_video_frame_buffer(img_wrapped_buffer); |
| 957 decoded_image.set_timestamp(timestamp); | 945 decoded_image.set_timestamp(timestamp); |
| 958 int ret = decode_complete_callback_->Decoded(decoded_image); | 946 int ret = decode_complete_callback_->Decoded(decoded_image); |
| 959 if (ret != 0) | 947 if (ret != 0) |
| 960 return ret; | 948 return ret; |
| 961 return WEBRTC_VIDEO_CODEC_OK; | 949 return WEBRTC_VIDEO_CODEC_OK; |
| 962 } | 950 } |
| 963 | 951 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 978 decoder_ = NULL; | 966 decoder_ = NULL; |
| 979 } | 967 } |
| 980 // Releases buffers from the pool. Any buffers not in use are deleted. Buffers | 968 // Releases buffers from the pool. Any buffers not in use are deleted. Buffers |
| 981 // still referenced externally are deleted once fully released, not returning | 969 // still referenced externally are deleted once fully released, not returning |
| 982 // to the pool. | 970 // to the pool. |
| 983 frame_buffer_pool_.ClearPool(); | 971 frame_buffer_pool_.ClearPool(); |
| 984 inited_ = false; | 972 inited_ = false; |
| 985 return WEBRTC_VIDEO_CODEC_OK; | 973 return WEBRTC_VIDEO_CODEC_OK; |
| 986 } | 974 } |
| 987 } // namespace webrtc | 975 } // namespace webrtc |
| OLD | NEW |