2015-02-18 18:42:55 +00:00
|
|
|
/*
|
2016-02-10 07:54:43 -08:00
|
|
|
* Copyright 2015 The WebRTC project authors. All Rights Reserved.
|
2015-02-18 18:42:55 +00:00
|
|
|
*
|
2016-02-10 07:54:43 -08:00
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
2015-02-18 18:42:55 +00:00
|
|
|
*/
|
|
|
|
|
|
2015-10-14 04:02:01 -07:00
|
|
|
#include <algorithm>
|
2017-02-17 03:26:10 -08:00
|
|
|
#include <deque>
|
2016-04-27 06:47:29 -07:00
|
|
|
#include <memory>
|
2015-02-18 18:42:55 +00:00
|
|
|
#include <vector>
|
|
|
|
|
|
Move talk/media to webrtc/media
I removed the 'libjingle' target in talk/libjingle.gyp and replaced
all users of it with base/base.gyp:rtc_base. It seems the jsoncpp
and expat dependencies were not used by it's previous references.
The files in talk/media/testdata were uploaded to Google Storage and
added .sha1 files in resources/media instead of simply moving them.
The previously disabled warnings that were inherited from
talk/build/common.gypi are now replaced by target-specific disabling
of only the failing warnings. Additional disabling was needed since the stricter
compilation warnings that applies to code in webrtc/.
License headers will be updated in a follow-up CL in order to not
break Git history.
Other modifications:
* Updated the header guards.
* Sorted the includes using chromium/src/tools/sort-headers.py
except for these files:
talk/app/webrtc/peerconnectionendtoend_unittest.cc
talk/app/webrtc/java/jni/androidmediadecoder_jni.cc
talk/app/webrtc/java/jni/androidmediaencoder_jni.cc
webrtc/media/devices/win32devicemanager.cc.
* Unused GYP reference to libjingle_tests_additional_deps was removed.
* Removed duplicated GYP entries of
webrtc/base/testutils.cc
webrtc/base/testutils.h
The HAVE_WEBRTC_VIDEO and HAVE_WEBRTC_VOICE defines were used by only talk/media,
so they were moved to the media.gyp.
I also checked that none of
EXPAT_RELATIVE_PATH,
FEATURE_ENABLE_VOICEMAIL,
GTEST_RELATIVE_PATH,
JSONCPP_RELATIVE_PATH,
LOGGING=1,
SRTP_RELATIVE_PATH,
FEATURE_ENABLE_SSL,
FEATURE_ENABLE_VOICEMAIL,
FEATURE_ENABLE_PSTN,
HAVE_SCTP,
HAVE_SRTP,
are used by the talk/media code.
For Chromium, the following changes will need to be applied to the roll CL that updates the
DEPS for WebRTC and libjingle: https://codereview.chromium.org/1604303002/
BUG=webrtc:5420
NOPRESUBMIT=True
TBR=tommi@webrtc.org
Review URL: https://codereview.webrtc.org/1587193006
Cr-Commit-Position: refs/heads/master@{#11495}
2016-02-04 23:52:28 -08:00
|
|
|
// NOTICE: androidmediadecoder_jni.h must be included before
|
|
|
|
|
// androidmediacodeccommon.h to avoid build errors.
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "sdk/android/src/jni/androidmediadecoder_jni.h"
|
2016-02-10 10:53:12 +01:00
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "common_video/h264/h264_bitstream_parser.h"
|
|
|
|
|
#include "common_video/include/i420_buffer_pool.h"
|
|
|
|
|
#include "modules/video_coding/include/video_codec_interface.h"
|
|
|
|
|
#include "modules/video_coding/utility/vp8_header_parser.h"
|
|
|
|
|
#include "rtc_base/bind.h"
|
|
|
|
|
#include "rtc_base/checks.h"
|
|
|
|
|
#include "rtc_base/logging.h"
|
2018-06-01 14:54:29 +02:00
|
|
|
#include "rtc_base/numerics/safe_conversions.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "rtc_base/scoped_ref_ptr.h"
|
|
|
|
|
#include "rtc_base/thread.h"
|
|
|
|
|
#include "rtc_base/timeutils.h"
|
2017-12-08 11:05:22 +01:00
|
|
|
#include "sdk/android/generated_video_jni/jni/MediaCodecVideoDecoder_jni.h"
|
2018-01-29 13:18:57 +01:00
|
|
|
#include "sdk/android/native_api/jni/java_types.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "sdk/android/src/jni/androidmediacodeccommon.h"
|
2017-11-14 17:08:59 +01:00
|
|
|
#include "sdk/android/src/jni/videoframe.h"
|
|
|
|
|
#include "third_party/libyuv/include/libyuv/convert.h"
|
|
|
|
|
#include "third_party/libyuv/include/libyuv/convert_from.h"
|
|
|
|
|
#include "third_party/libyuv/include/libyuv/video_common.h"
|
2015-02-18 18:42:55 +00:00
|
|
|
|
|
|
|
|
using rtc::Bind;
|
|
|
|
|
using rtc::Thread;
|
|
|
|
|
using rtc::ThreadManager;
|
|
|
|
|
|
2017-08-28 16:24:06 -07:00
|
|
|
namespace webrtc {
|
|
|
|
|
namespace jni {
|
2015-02-18 18:42:55 +00:00
|
|
|
|
Revert of Deliver video frames on Android, on the decode thread. (patchset #7 id:120001 of https://codereview.webrtc.org/2764573002/ )
Reason for revert:
Breaks Chrome FYI Android bots.
See:
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus9%29/builds/20418
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus6%29/builds/14724
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus5%29/builds/20133
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28K%20Nexus5%29/builds/15111
Original issue's description:
> Deliver video frames on Android, on the decode thread.
>
> VideoCoding
> * Adding a method for polling for frames on Android only until the capture implementation takes care of this (longer term plan).
>
> CodecDatabase
> * Add an accessor for the current decoder
> * Use std::unique_ptr<> for ownership.
> * Remove "Release()" and "ReleaseDecoder()". Instead just delete.
> * Remove |friend| relationship between CodecDatabase and VCMGenericDecoder.
>
> VCMDecodedFrameCallback
> * DCHECKs for thread correctness.
> * Remove |lock_| now that a threading model has been established and verified.
>
> VCMGenericDecoder
> * All methods now have thread checks.
> * Variable access associated with thread checkers.
>
> VideoReceiver
> * Added two notification methods, DecoderThreadStarting() and DecoderThreadStopped()
> * Allows us to establish a period when the decoder thread is not running and it is safe to modify variables such as callbacks, that are only read when the decoder thread is running.
> * Allows us to DCHECK thread guarantees.
> * Allows synchronizing callbacks from the module process thread and have them only active while the decoder thread is running.
> * The above, allows us to establish two modes for the thread, single-threaded-mutable and multi-threaded-const.
> * Using that knowledge, we can remove |receive_crit_| as well as locking for a number of member variables.
>
> MediaCodecVideoDecoder
> * Removed frame polling code from this class, since this is now done from the root thread function in VideoReceiveStream.
>
> VideoReceiveStream
> * On Android: Polls for decoded frames every 10ms (same interval as previously in MediaCodecVideoDecoder)
> * [Un]Registers the |video_receiver_| with the module thread only around the time the decoder thread is started/stopped.
> * Notifies the receiver of start/stop events of the decoder thread.
> * Changed the decoder thread to use the new PlatformThread callback type.
>
> BUG=webrtc:7361, 695438
>
> Review-Url: https://codereview.webrtc.org/2764573002
> Cr-Commit-Position: refs/heads/master@{#17527}
> Committed: https://chromium.googlesource.com/external/webrtc/+/e3aa88bbd5accadec73fa7e38584dfbf6aabe8a9
TBR=sakal@webrtc.org,mflodman@webrtc.org,stefan@webrtc.org,tommi@webrtc.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=webrtc:7361, 695438
Review-Url: https://codereview.webrtc.org/2792033003
Cr-Commit-Position: refs/heads/master@{#17530}
2017-04-04 07:16:21 -07:00
|
|
|
// Logging macros.
|
|
|
|
|
#define TAG_DECODER "MediaCodecVideoDecoder"
|
|
|
|
|
#ifdef TRACK_BUFFER_TIMING
|
2017-07-14 14:44:46 -07:00
|
|
|
#define ALOGV(...) \
|
Revert of Deliver video frames on Android, on the decode thread. (patchset #7 id:120001 of https://codereview.webrtc.org/2764573002/ )
Reason for revert:
Breaks Chrome FYI Android bots.
See:
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus9%29/builds/20418
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus6%29/builds/14724
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus5%29/builds/20133
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28K%20Nexus5%29/builds/15111
Original issue's description:
> Deliver video frames on Android, on the decode thread.
>
> VideoCoding
> * Adding a method for polling for frames on Android only until the capture implementation takes care of this (longer term plan).
>
> CodecDatabase
> * Add an accessor for the current decoder
> * Use std::unique_ptr<> for ownership.
> * Remove "Release()" and "ReleaseDecoder()". Instead just delete.
> * Remove |friend| relationship between CodecDatabase and VCMGenericDecoder.
>
> VCMDecodedFrameCallback
> * DCHECKs for thread correctness.
> * Remove |lock_| now that a threading model has been established and verified.
>
> VCMGenericDecoder
> * All methods now have thread checks.
> * Variable access associated with thread checkers.
>
> VideoReceiver
> * Added two notification methods, DecoderThreadStarting() and DecoderThreadStopped()
> * Allows us to establish a period when the decoder thread is not running and it is safe to modify variables such as callbacks, that are only read when the decoder thread is running.
> * Allows us to DCHECK thread guarantees.
> * Allows synchronizing callbacks from the module process thread and have them only active while the decoder thread is running.
> * The above, allows us to establish two modes for the thread, single-threaded-mutable and multi-threaded-const.
> * Using that knowledge, we can remove |receive_crit_| as well as locking for a number of member variables.
>
> MediaCodecVideoDecoder
> * Removed frame polling code from this class, since this is now done from the root thread function in VideoReceiveStream.
>
> VideoReceiveStream
> * On Android: Polls for decoded frames every 10ms (same interval as previously in MediaCodecVideoDecoder)
> * [Un]Registers the |video_receiver_| with the module thread only around the time the decoder thread is started/stopped.
> * Notifies the receiver of start/stop events of the decoder thread.
> * Changed the decoder thread to use the new PlatformThread callback type.
>
> BUG=webrtc:7361, 695438
>
> Review-Url: https://codereview.webrtc.org/2764573002
> Cr-Commit-Position: refs/heads/master@{#17527}
> Committed: https://chromium.googlesource.com/external/webrtc/+/e3aa88bbd5accadec73fa7e38584dfbf6aabe8a9
TBR=sakal@webrtc.org,mflodman@webrtc.org,stefan@webrtc.org,tommi@webrtc.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=webrtc:7361, 695438
Review-Url: https://codereview.webrtc.org/2792033003
Cr-Commit-Position: refs/heads/master@{#17530}
2017-04-04 07:16:21 -07:00
|
|
|
__android_log_print(ANDROID_LOG_VERBOSE, TAG_DECODER, __VA_ARGS__)
|
|
|
|
|
#else
|
|
|
|
|
#define ALOGV(...)
|
|
|
|
|
#endif
|
2017-11-09 11:09:25 +01:00
|
|
|
#define ALOGD RTC_LOG_TAG(rtc::LS_INFO, TAG_DECODER)
|
|
|
|
|
#define ALOGW RTC_LOG_TAG(rtc::LS_WARNING, TAG_DECODER)
|
|
|
|
|
#define ALOGE RTC_LOG_TAG(rtc::LS_ERROR, TAG_DECODER)
|
Revert of Deliver video frames on Android, on the decode thread. (patchset #7 id:120001 of https://codereview.webrtc.org/2764573002/ )
Reason for revert:
Breaks Chrome FYI Android bots.
See:
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus9%29/builds/20418
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus6%29/builds/14724
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus5%29/builds/20133
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28K%20Nexus5%29/builds/15111
Original issue's description:
> Deliver video frames on Android, on the decode thread.
>
> VideoCoding
> * Adding a method for polling for frames on Android only until the capture implementation takes care of this (longer term plan).
>
> CodecDatabase
> * Add an accessor for the current decoder
> * Use std::unique_ptr<> for ownership.
> * Remove "Release()" and "ReleaseDecoder()". Instead just delete.
> * Remove |friend| relationship between CodecDatabase and VCMGenericDecoder.
>
> VCMDecodedFrameCallback
> * DCHECKs for thread correctness.
> * Remove |lock_| now that a threading model has been established and verified.
>
> VCMGenericDecoder
> * All methods now have thread checks.
> * Variable access associated with thread checkers.
>
> VideoReceiver
> * Added two notification methods, DecoderThreadStarting() and DecoderThreadStopped()
> * Allows us to establish a period when the decoder thread is not running and it is safe to modify variables such as callbacks, that are only read when the decoder thread is running.
> * Allows us to DCHECK thread guarantees.
> * Allows synchronizing callbacks from the module process thread and have them only active while the decoder thread is running.
> * The above, allows us to establish two modes for the thread, single-threaded-mutable and multi-threaded-const.
> * Using that knowledge, we can remove |receive_crit_| as well as locking for a number of member variables.
>
> MediaCodecVideoDecoder
> * Removed frame polling code from this class, since this is now done from the root thread function in VideoReceiveStream.
>
> VideoReceiveStream
> * On Android: Polls for decoded frames every 10ms (same interval as previously in MediaCodecVideoDecoder)
> * [Un]Registers the |video_receiver_| with the module thread only around the time the decoder thread is started/stopped.
> * Notifies the receiver of start/stop events of the decoder thread.
> * Changed the decoder thread to use the new PlatformThread callback type.
>
> BUG=webrtc:7361, 695438
>
> Review-Url: https://codereview.webrtc.org/2764573002
> Cr-Commit-Position: refs/heads/master@{#17527}
> Committed: https://chromium.googlesource.com/external/webrtc/+/e3aa88bbd5accadec73fa7e38584dfbf6aabe8a9
TBR=sakal@webrtc.org,mflodman@webrtc.org,stefan@webrtc.org,tommi@webrtc.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=webrtc:7361, 695438
Review-Url: https://codereview.webrtc.org/2792033003
Cr-Commit-Position: refs/heads/master@{#17530}
2017-04-04 07:16:21 -07:00
|
|
|
|
|
|
|
|
enum { kMaxWarningLogFrames = 2 };
|
|
|
|
|
|
2017-08-28 16:24:06 -07:00
|
|
|
class MediaCodecVideoDecoder : public VideoDecoder, public rtc::MessageHandler {
|
2015-02-18 18:42:55 +00:00
|
|
|
public:
|
2015-09-01 15:04:13 -07:00
|
|
|
explicit MediaCodecVideoDecoder(JNIEnv* jni,
|
|
|
|
|
VideoCodecType codecType,
|
|
|
|
|
jobject render_egl_context);
|
2018-04-05 11:42:24 +02:00
|
|
|
~MediaCodecVideoDecoder() override;
|
2015-02-18 18:42:55 +00:00
|
|
|
|
|
|
|
|
int32_t InitDecode(const VideoCodec* codecSettings,
|
|
|
|
|
int32_t numberOfCores) override;
|
|
|
|
|
|
|
|
|
|
int32_t Decode(const EncodedImage& inputImage,
|
|
|
|
|
bool missingFrames,
|
|
|
|
|
const CodecSpecificInfo* codecSpecificInfo = NULL,
|
|
|
|
|
int64_t renderTimeMs = -1) override;
|
|
|
|
|
|
|
|
|
|
int32_t RegisterDecodeCompleteCallback(
|
|
|
|
|
DecodedImageCallback* callback) override;
|
|
|
|
|
|
|
|
|
|
int32_t Release() override;
|
|
|
|
|
|
2015-12-10 09:27:38 -08:00
|
|
|
bool PrefersLateDecoding() const override { return true; }
|
|
|
|
|
|
Revert of Deliver video frames on Android, on the decode thread. (patchset #7 id:120001 of https://codereview.webrtc.org/2764573002/ )
Reason for revert:
Breaks Chrome FYI Android bots.
See:
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus9%29/builds/20418
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus6%29/builds/14724
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus5%29/builds/20133
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28K%20Nexus5%29/builds/15111
Original issue's description:
> Deliver video frames on Android, on the decode thread.
>
> VideoCoding
> * Adding a method for polling for frames on Android only until the capture implementation takes care of this (longer term plan).
>
> CodecDatabase
> * Add an accessor for the current decoder
> * Use std::unique_ptr<> for ownership.
> * Remove "Release()" and "ReleaseDecoder()". Instead just delete.
> * Remove |friend| relationship between CodecDatabase and VCMGenericDecoder.
>
> VCMDecodedFrameCallback
> * DCHECKs for thread correctness.
> * Remove |lock_| now that a threading model has been established and verified.
>
> VCMGenericDecoder
> * All methods now have thread checks.
> * Variable access associated with thread checkers.
>
> VideoReceiver
> * Added two notification methods, DecoderThreadStarting() and DecoderThreadStopped()
> * Allows us to establish a period when the decoder thread is not running and it is safe to modify variables such as callbacks, that are only read when the decoder thread is running.
> * Allows us to DCHECK thread guarantees.
> * Allows synchronizing callbacks from the module process thread and have them only active while the decoder thread is running.
> * The above, allows us to establish two modes for the thread, single-threaded-mutable and multi-threaded-const.
> * Using that knowledge, we can remove |receive_crit_| as well as locking for a number of member variables.
>
> MediaCodecVideoDecoder
> * Removed frame polling code from this class, since this is now done from the root thread function in VideoReceiveStream.
>
> VideoReceiveStream
> * On Android: Polls for decoded frames every 10ms (same interval as previously in MediaCodecVideoDecoder)
> * [Un]Registers the |video_receiver_| with the module thread only around the time the decoder thread is started/stopped.
> * Notifies the receiver of start/stop events of the decoder thread.
> * Changed the decoder thread to use the new PlatformThread callback type.
>
> BUG=webrtc:7361, 695438
>
> Review-Url: https://codereview.webrtc.org/2764573002
> Cr-Commit-Position: refs/heads/master@{#17527}
> Committed: https://chromium.googlesource.com/external/webrtc/+/e3aa88bbd5accadec73fa7e38584dfbf6aabe8a9
TBR=sakal@webrtc.org,mflodman@webrtc.org,stefan@webrtc.org,tommi@webrtc.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=webrtc:7361, 695438
Review-Url: https://codereview.webrtc.org/2792033003
Cr-Commit-Position: refs/heads/master@{#17530}
2017-04-04 07:16:21 -07:00
|
|
|
// rtc::MessageHandler implementation.
|
|
|
|
|
void OnMessage(rtc::Message* msg) override;
|
|
|
|
|
|
2015-12-18 16:01:11 +01:00
|
|
|
const char* ImplementationName() const override;
|
|
|
|
|
|
2015-02-18 18:42:55 +00:00
|
|
|
private:
|
Revert of Deliver video frames on Android, on the decode thread. (patchset #7 id:120001 of https://codereview.webrtc.org/2764573002/ )
Reason for revert:
Breaks Chrome FYI Android bots.
See:
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus9%29/builds/20418
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus6%29/builds/14724
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus5%29/builds/20133
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28K%20Nexus5%29/builds/15111
Original issue's description:
> Deliver video frames on Android, on the decode thread.
>
> VideoCoding
> * Adding a method for polling for frames on Android only until the capture implementation takes care of this (longer term plan).
>
> CodecDatabase
> * Add an accessor for the current decoder
> * Use std::unique_ptr<> for ownership.
> * Remove "Release()" and "ReleaseDecoder()". Instead just delete.
> * Remove |friend| relationship between CodecDatabase and VCMGenericDecoder.
>
> VCMDecodedFrameCallback
> * DCHECKs for thread correctness.
> * Remove |lock_| now that a threading model has been established and verified.
>
> VCMGenericDecoder
> * All methods now have thread checks.
> * Variable access associated with thread checkers.
>
> VideoReceiver
> * Added two notification methods, DecoderThreadStarting() and DecoderThreadStopped()
> * Allows us to establish a period when the decoder thread is not running and it is safe to modify variables such as callbacks, that are only read when the decoder thread is running.
> * Allows us to DCHECK thread guarantees.
> * Allows synchronizing callbacks from the module process thread and have them only active while the decoder thread is running.
> * The above, allows us to establish two modes for the thread, single-threaded-mutable and multi-threaded-const.
> * Using that knowledge, we can remove |receive_crit_| as well as locking for a number of member variables.
>
> MediaCodecVideoDecoder
> * Removed frame polling code from this class, since this is now done from the root thread function in VideoReceiveStream.
>
> VideoReceiveStream
> * On Android: Polls for decoded frames every 10ms (same interval as previously in MediaCodecVideoDecoder)
> * [Un]Registers the |video_receiver_| with the module thread only around the time the decoder thread is started/stopped.
> * Notifies the receiver of start/stop events of the decoder thread.
> * Changed the decoder thread to use the new PlatformThread callback type.
>
> BUG=webrtc:7361, 695438
>
> Review-Url: https://codereview.webrtc.org/2764573002
> Cr-Commit-Position: refs/heads/master@{#17527}
> Committed: https://chromium.googlesource.com/external/webrtc/+/e3aa88bbd5accadec73fa7e38584dfbf6aabe8a9
TBR=sakal@webrtc.org,mflodman@webrtc.org,stefan@webrtc.org,tommi@webrtc.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=webrtc:7361, 695438
Review-Url: https://codereview.webrtc.org/2792033003
Cr-Commit-Position: refs/heads/master@{#17530}
2017-04-04 07:16:21 -07:00
|
|
|
// CHECK-fail if not running on |codec_thread_|.
|
|
|
|
|
void CheckOnCodecThread();
|
2015-02-18 18:42:55 +00:00
|
|
|
|
|
|
|
|
int32_t InitDecodeOnCodecThread();
|
2016-03-04 14:10:50 -08:00
|
|
|
int32_t ResetDecodeOnCodecThread();
|
2015-02-18 18:42:55 +00:00
|
|
|
int32_t ReleaseOnCodecThread();
|
Revert of Deliver video frames on Android, on the decode thread. (patchset #7 id:120001 of https://codereview.webrtc.org/2764573002/ )
Reason for revert:
Breaks Chrome FYI Android bots.
See:
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus9%29/builds/20418
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus6%29/builds/14724
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus5%29/builds/20133
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28K%20Nexus5%29/builds/15111
Original issue's description:
> Deliver video frames on Android, on the decode thread.
>
> VideoCoding
> * Adding a method for polling for frames on Android only until the capture implementation takes care of this (longer term plan).
>
> CodecDatabase
> * Add an accessor for the current decoder
> * Use std::unique_ptr<> for ownership.
> * Remove "Release()" and "ReleaseDecoder()". Instead just delete.
> * Remove |friend| relationship between CodecDatabase and VCMGenericDecoder.
>
> VCMDecodedFrameCallback
> * DCHECKs for thread correctness.
> * Remove |lock_| now that a threading model has been established and verified.
>
> VCMGenericDecoder
> * All methods now have thread checks.
> * Variable access associated with thread checkers.
>
> VideoReceiver
> * Added two notification methods, DecoderThreadStarting() and DecoderThreadStopped()
> * Allows us to establish a period when the decoder thread is not running and it is safe to modify variables such as callbacks, that are only read when the decoder thread is running.
> * Allows us to DCHECK thread guarantees.
> * Allows synchronizing callbacks from the module process thread and have them only active while the decoder thread is running.
> * The above, allows us to establish two modes for the thread, single-threaded-mutable and multi-threaded-const.
> * Using that knowledge, we can remove |receive_crit_| as well as locking for a number of member variables.
>
> MediaCodecVideoDecoder
> * Removed frame polling code from this class, since this is now done from the root thread function in VideoReceiveStream.
>
> VideoReceiveStream
> * On Android: Polls for decoded frames every 10ms (same interval as previously in MediaCodecVideoDecoder)
> * [Un]Registers the |video_receiver_| with the module thread only around the time the decoder thread is started/stopped.
> * Notifies the receiver of start/stop events of the decoder thread.
> * Changed the decoder thread to use the new PlatformThread callback type.
>
> BUG=webrtc:7361, 695438
>
> Review-Url: https://codereview.webrtc.org/2764573002
> Cr-Commit-Position: refs/heads/master@{#17527}
> Committed: https://chromium.googlesource.com/external/webrtc/+/e3aa88bbd5accadec73fa7e38584dfbf6aabe8a9
TBR=sakal@webrtc.org,mflodman@webrtc.org,stefan@webrtc.org,tommi@webrtc.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=webrtc:7361, 695438
Review-Url: https://codereview.webrtc.org/2792033003
Cr-Commit-Position: refs/heads/master@{#17530}
2017-04-04 07:16:21 -07:00
|
|
|
int32_t DecodeOnCodecThread(const EncodedImage& inputImage);
|
2015-02-18 18:42:55 +00:00
|
|
|
// Deliver any outputs pending in the MediaCodec to our |callback_| and return
|
|
|
|
|
// true on success.
|
Revert of Deliver video frames on Android, on the decode thread. (patchset #7 id:120001 of https://codereview.webrtc.org/2764573002/ )
Reason for revert:
Breaks Chrome FYI Android bots.
See:
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus9%29/builds/20418
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus6%29/builds/14724
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus5%29/builds/20133
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28K%20Nexus5%29/builds/15111
Original issue's description:
> Deliver video frames on Android, on the decode thread.
>
> VideoCoding
> * Adding a method for polling for frames on Android only until the capture implementation takes care of this (longer term plan).
>
> CodecDatabase
> * Add an accessor for the current decoder
> * Use std::unique_ptr<> for ownership.
> * Remove "Release()" and "ReleaseDecoder()". Instead just delete.
> * Remove |friend| relationship between CodecDatabase and VCMGenericDecoder.
>
> VCMDecodedFrameCallback
> * DCHECKs for thread correctness.
> * Remove |lock_| now that a threading model has been established and verified.
>
> VCMGenericDecoder
> * All methods now have thread checks.
> * Variable access associated with thread checkers.
>
> VideoReceiver
> * Added two notification methods, DecoderThreadStarting() and DecoderThreadStopped()
> * Allows us to establish a period when the decoder thread is not running and it is safe to modify variables such as callbacks, that are only read when the decoder thread is running.
> * Allows us to DCHECK thread guarantees.
> * Allows synchronizing callbacks from the module process thread and have them only active while the decoder thread is running.
> * The above, allows us to establish two modes for the thread, single-threaded-mutable and multi-threaded-const.
> * Using that knowledge, we can remove |receive_crit_| as well as locking for a number of member variables.
>
> MediaCodecVideoDecoder
> * Removed frame polling code from this class, since this is now done from the root thread function in VideoReceiveStream.
>
> VideoReceiveStream
> * On Android: Polls for decoded frames every 10ms (same interval as previously in MediaCodecVideoDecoder)
> * [Un]Registers the |video_receiver_| with the module thread only around the time the decoder thread is started/stopped.
> * Notifies the receiver of start/stop events of the decoder thread.
> * Changed the decoder thread to use the new PlatformThread callback type.
>
> BUG=webrtc:7361, 695438
>
> Review-Url: https://codereview.webrtc.org/2764573002
> Cr-Commit-Position: refs/heads/master@{#17527}
> Committed: https://chromium.googlesource.com/external/webrtc/+/e3aa88bbd5accadec73fa7e38584dfbf6aabe8a9
TBR=sakal@webrtc.org,mflodman@webrtc.org,stefan@webrtc.org,tommi@webrtc.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=webrtc:7361, 695438
Review-Url: https://codereview.webrtc.org/2792033003
Cr-Commit-Position: refs/heads/master@{#17530}
2017-04-04 07:16:21 -07:00
|
|
|
bool DeliverPendingOutputs(JNIEnv* jni, int dequeue_timeout_us);
|
2015-06-12 16:40:44 -07:00
|
|
|
int32_t ProcessHWErrorOnCodecThread();
|
2016-02-04 11:47:12 -08:00
|
|
|
void EnableFrameLogOnWarning();
|
2016-03-04 14:10:50 -08:00
|
|
|
void ResetVariables();
|
2015-02-18 18:42:55 +00:00
|
|
|
|
2015-02-23 17:44:27 +00:00
|
|
|
// Type of video codec.
|
|
|
|
|
VideoCodecType codecType_;
|
|
|
|
|
|
2016-01-04 10:15:53 -08:00
|
|
|
// Render EGL context - owned by factory, should not be allocated/destroyed
|
|
|
|
|
// by VideoDecoder.
|
|
|
|
|
jobject render_egl_context_;
|
|
|
|
|
|
2015-02-18 18:42:55 +00:00
|
|
|
bool key_frame_required_;
|
|
|
|
|
bool inited_;
|
2015-06-12 16:40:44 -07:00
|
|
|
bool sw_fallback_required_;
|
2015-02-18 18:42:55 +00:00
|
|
|
bool use_surface_;
|
|
|
|
|
VideoCodec codec_;
|
2017-08-28 16:24:06 -07:00
|
|
|
I420BufferPool decoded_frame_pool_;
|
2015-02-18 18:42:55 +00:00
|
|
|
DecodedImageCallback* callback_;
|
|
|
|
|
int frames_received_; // Number of frames received by decoder.
|
2015-02-23 17:44:27 +00:00
|
|
|
int frames_decoded_; // Number of frames decoded by decoder.
|
2016-02-04 11:47:12 -08:00
|
|
|
// Number of decoded frames for which log information is displayed.
|
|
|
|
|
int frames_decoded_logged_;
|
2015-02-18 18:42:55 +00:00
|
|
|
int64_t start_time_ms_; // Start time for statistics.
|
|
|
|
|
int current_frames_; // Number of frames in the current statistics interval.
|
|
|
|
|
int current_bytes_; // Encoded bytes in the current statistics interval.
|
|
|
|
|
int current_decoding_time_ms_; // Overall decoding time in the current second
|
2016-02-05 14:05:08 -08:00
|
|
|
int current_delay_time_ms_; // Overall delay time in the current second.
|
2018-06-01 14:54:29 +02:00
|
|
|
int32_t max_pending_frames_; // Maximum number of pending input frames.
|
2017-08-28 16:24:06 -07:00
|
|
|
H264BitstreamParser h264_bitstream_parser_;
|
2018-06-21 10:17:24 +02:00
|
|
|
std::deque<absl::optional<uint8_t>> pending_frame_qps_;
|
2015-02-18 18:42:55 +00:00
|
|
|
|
|
|
|
|
// State that is constant for the lifetime of this object once the ctor
|
|
|
|
|
// returns.
|
2016-04-27 06:47:29 -07:00
|
|
|
std::unique_ptr<Thread>
|
|
|
|
|
codec_thread_; // Thread on which to operate MediaCodec.
|
2017-12-20 15:12:10 +01:00
|
|
|
ScopedJavaGlobalRef<jobject> j_media_codec_video_decoder_;
|
2015-02-18 18:42:55 +00:00
|
|
|
|
|
|
|
|
// Global references; must be deleted in Release().
|
2017-12-20 15:12:10 +01:00
|
|
|
std::vector<ScopedJavaGlobalRef<jobject>> input_buffers_;
|
2015-02-18 18:42:55 +00:00
|
|
|
};
|
|
|
|
|
|
2017-07-14 14:44:46 -07:00
|
|
|
MediaCodecVideoDecoder::MediaCodecVideoDecoder(JNIEnv* jni,
|
|
|
|
|
VideoCodecType codecType,
|
|
|
|
|
jobject render_egl_context)
|
|
|
|
|
: codecType_(codecType),
|
|
|
|
|
render_egl_context_(render_egl_context),
|
|
|
|
|
key_frame_required_(true),
|
|
|
|
|
inited_(false),
|
|
|
|
|
sw_fallback_required_(false),
|
|
|
|
|
codec_thread_(Thread::Create()),
|
|
|
|
|
j_media_codec_video_decoder_(
|
|
|
|
|
jni,
|
2017-12-08 11:05:22 +01:00
|
|
|
Java_MediaCodecVideoDecoder_Constructor(jni)) {
|
2015-02-18 18:42:55 +00:00
|
|
|
codec_thread_->SetName("MediaCodecVideoDecoder", NULL);
|
Revert of Deliver video frames on Android, on the decode thread. (patchset #7 id:120001 of https://codereview.webrtc.org/2764573002/ )
Reason for revert:
Breaks Chrome FYI Android bots.
See:
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus9%29/builds/20418
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus6%29/builds/14724
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus5%29/builds/20133
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28K%20Nexus5%29/builds/15111
Original issue's description:
> Deliver video frames on Android, on the decode thread.
>
> VideoCoding
> * Adding a method for polling for frames on Android only until the capture implementation takes care of this (longer term plan).
>
> CodecDatabase
> * Add an accessor for the current decoder
> * Use std::unique_ptr<> for ownership.
> * Remove "Release()" and "ReleaseDecoder()". Instead just delete.
> * Remove |friend| relationship between CodecDatabase and VCMGenericDecoder.
>
> VCMDecodedFrameCallback
> * DCHECKs for thread correctness.
> * Remove |lock_| now that a threading model has been established and verified.
>
> VCMGenericDecoder
> * All methods now have thread checks.
> * Variable access associated with thread checkers.
>
> VideoReceiver
> * Added two notification methods, DecoderThreadStarting() and DecoderThreadStopped()
> * Allows us to establish a period when the decoder thread is not running and it is safe to modify variables such as callbacks, that are only read when the decoder thread is running.
> * Allows us to DCHECK thread guarantees.
> * Allows synchronizing callbacks from the module process thread and have them only active while the decoder thread is running.
> * The above, allows us to establish two modes for the thread, single-threaded-mutable and multi-threaded-const.
> * Using that knowledge, we can remove |receive_crit_| as well as locking for a number of member variables.
>
> MediaCodecVideoDecoder
> * Removed frame polling code from this class, since this is now done from the root thread function in VideoReceiveStream.
>
> VideoReceiveStream
> * On Android: Polls for decoded frames every 10ms (same interval as previously in MediaCodecVideoDecoder)
> * [Un]Registers the |video_receiver_| with the module thread only around the time the decoder thread is started/stopped.
> * Notifies the receiver of start/stop events of the decoder thread.
> * Changed the decoder thread to use the new PlatformThread callback type.
>
> BUG=webrtc:7361, 695438
>
> Review-Url: https://codereview.webrtc.org/2764573002
> Cr-Commit-Position: refs/heads/master@{#17527}
> Committed: https://chromium.googlesource.com/external/webrtc/+/e3aa88bbd5accadec73fa7e38584dfbf6aabe8a9
TBR=sakal@webrtc.org,mflodman@webrtc.org,stefan@webrtc.org,tommi@webrtc.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=webrtc:7361, 695438
Review-Url: https://codereview.webrtc.org/2792033003
Cr-Commit-Position: refs/heads/master@{#17530}
2017-04-04 07:16:21 -07:00
|
|
|
RTC_CHECK(codec_thread_->Start()) << "Failed to start MediaCodecVideoDecoder";
|
2015-02-18 18:42:55 +00:00
|
|
|
|
2015-09-16 12:32:21 +02:00
|
|
|
use_surface_ = (render_egl_context_ != NULL);
|
2015-10-07 16:51:02 -07:00
|
|
|
ALOGD << "MediaCodecVideoDecoder ctor. Use surface: " << use_surface_;
|
2015-02-18 18:42:55 +00:00
|
|
|
memset(&codec_, 0, sizeof(codec_));
|
|
|
|
|
AllowBlockingCalls();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MediaCodecVideoDecoder::~MediaCodecVideoDecoder() {
|
|
|
|
|
// Call Release() to ensure no more callbacks to us after we are deleted.
|
|
|
|
|
Release();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int32_t MediaCodecVideoDecoder::InitDecode(const VideoCodec* inst,
|
|
|
|
|
int32_t numberOfCores) {
|
2015-10-07 16:51:02 -07:00
|
|
|
ALOGD << "InitDecode.";
|
2015-02-18 18:42:55 +00:00
|
|
|
if (inst == NULL) {
|
2015-10-07 16:51:02 -07:00
|
|
|
ALOGE << "NULL VideoCodec instance";
|
2015-02-18 18:42:55 +00:00
|
|
|
return WEBRTC_VIDEO_CODEC_ERR_PARAMETER;
|
|
|
|
|
}
|
2015-02-23 17:44:27 +00:00
|
|
|
// Factory should guard against other codecs being used with us.
|
Revert of Deliver video frames on Android, on the decode thread. (patchset #7 id:120001 of https://codereview.webrtc.org/2764573002/ )
Reason for revert:
Breaks Chrome FYI Android bots.
See:
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus9%29/builds/20418
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus6%29/builds/14724
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus5%29/builds/20133
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28K%20Nexus5%29/builds/15111
Original issue's description:
> Deliver video frames on Android, on the decode thread.
>
> VideoCoding
> * Adding a method for polling for frames on Android only until the capture implementation takes care of this (longer term plan).
>
> CodecDatabase
> * Add an accessor for the current decoder
> * Use std::unique_ptr<> for ownership.
> * Remove "Release()" and "ReleaseDecoder()". Instead just delete.
> * Remove |friend| relationship between CodecDatabase and VCMGenericDecoder.
>
> VCMDecodedFrameCallback
> * DCHECKs for thread correctness.
> * Remove |lock_| now that a threading model has been established and verified.
>
> VCMGenericDecoder
> * All methods now have thread checks.
> * Variable access associated with thread checkers.
>
> VideoReceiver
> * Added two notification methods, DecoderThreadStarting() and DecoderThreadStopped()
> * Allows us to establish a period when the decoder thread is not running and it is safe to modify variables such as callbacks, that are only read when the decoder thread is running.
> * Allows us to DCHECK thread guarantees.
> * Allows synchronizing callbacks from the module process thread and have them only active while the decoder thread is running.
> * The above, allows us to establish two modes for the thread, single-threaded-mutable and multi-threaded-const.
> * Using that knowledge, we can remove |receive_crit_| as well as locking for a number of member variables.
>
> MediaCodecVideoDecoder
> * Removed frame polling code from this class, since this is now done from the root thread function in VideoReceiveStream.
>
> VideoReceiveStream
> * On Android: Polls for decoded frames every 10ms (same interval as previously in MediaCodecVideoDecoder)
> * [Un]Registers the |video_receiver_| with the module thread only around the time the decoder thread is started/stopped.
> * Notifies the receiver of start/stop events of the decoder thread.
> * Changed the decoder thread to use the new PlatformThread callback type.
>
> BUG=webrtc:7361, 695438
>
> Review-Url: https://codereview.webrtc.org/2764573002
> Cr-Commit-Position: refs/heads/master@{#17527}
> Committed: https://chromium.googlesource.com/external/webrtc/+/e3aa88bbd5accadec73fa7e38584dfbf6aabe8a9
TBR=sakal@webrtc.org,mflodman@webrtc.org,stefan@webrtc.org,tommi@webrtc.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=webrtc:7361, 695438
Review-Url: https://codereview.webrtc.org/2792033003
Cr-Commit-Position: refs/heads/master@{#17530}
2017-04-04 07:16:21 -07:00
|
|
|
RTC_CHECK(inst->codecType == codecType_)
|
2015-09-17 00:24:34 -07:00
|
|
|
<< "Unsupported codec " << inst->codecType << " for " << codecType_;
|
2015-02-23 17:44:27 +00:00
|
|
|
|
2015-06-12 16:40:44 -07:00
|
|
|
if (sw_fallback_required_) {
|
2015-10-07 16:51:02 -07:00
|
|
|
ALOGE << "InitDecode() - fallback to SW decoder";
|
2015-06-12 16:40:44 -07:00
|
|
|
return WEBRTC_VIDEO_CODEC_OK;
|
2015-02-18 18:42:55 +00:00
|
|
|
}
|
|
|
|
|
// Save VideoCodec instance for later.
|
|
|
|
|
if (&codec_ != inst) {
|
|
|
|
|
codec_ = *inst;
|
|
|
|
|
}
|
2015-10-28 10:30:32 -07:00
|
|
|
// If maxFramerate is not set then assume 30 fps.
|
|
|
|
|
codec_.maxFramerate = (codec_.maxFramerate >= 1) ? codec_.maxFramerate : 30;
|
2015-02-18 18:42:55 +00:00
|
|
|
|
|
|
|
|
// Call Java init.
|
|
|
|
|
return codec_thread_->Invoke<int32_t>(
|
2016-06-10 14:17:27 -07:00
|
|
|
RTC_FROM_HERE,
|
2015-02-18 18:42:55 +00:00
|
|
|
Bind(&MediaCodecVideoDecoder::InitDecodeOnCodecThread, this));
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-04 14:10:50 -08:00
|
|
|
void MediaCodecVideoDecoder::ResetVariables() {
|
Revert of Deliver video frames on Android, on the decode thread. (patchset #7 id:120001 of https://codereview.webrtc.org/2764573002/ )
Reason for revert:
Breaks Chrome FYI Android bots.
See:
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus9%29/builds/20418
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus6%29/builds/14724
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus5%29/builds/20133
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28K%20Nexus5%29/builds/15111
Original issue's description:
> Deliver video frames on Android, on the decode thread.
>
> VideoCoding
> * Adding a method for polling for frames on Android only until the capture implementation takes care of this (longer term plan).
>
> CodecDatabase
> * Add an accessor for the current decoder
> * Use std::unique_ptr<> for ownership.
> * Remove "Release()" and "ReleaseDecoder()". Instead just delete.
> * Remove |friend| relationship between CodecDatabase and VCMGenericDecoder.
>
> VCMDecodedFrameCallback
> * DCHECKs for thread correctness.
> * Remove |lock_| now that a threading model has been established and verified.
>
> VCMGenericDecoder
> * All methods now have thread checks.
> * Variable access associated with thread checkers.
>
> VideoReceiver
> * Added two notification methods, DecoderThreadStarting() and DecoderThreadStopped()
> * Allows us to establish a period when the decoder thread is not running and it is safe to modify variables such as callbacks, that are only read when the decoder thread is running.
> * Allows us to DCHECK thread guarantees.
> * Allows synchronizing callbacks from the module process thread and have them only active while the decoder thread is running.
> * The above, allows us to establish two modes for the thread, single-threaded-mutable and multi-threaded-const.
> * Using that knowledge, we can remove |receive_crit_| as well as locking for a number of member variables.
>
> MediaCodecVideoDecoder
> * Removed frame polling code from this class, since this is now done from the root thread function in VideoReceiveStream.
>
> VideoReceiveStream
> * On Android: Polls for decoded frames every 10ms (same interval as previously in MediaCodecVideoDecoder)
> * [Un]Registers the |video_receiver_| with the module thread only around the time the decoder thread is started/stopped.
> * Notifies the receiver of start/stop events of the decoder thread.
> * Changed the decoder thread to use the new PlatformThread callback type.
>
> BUG=webrtc:7361, 695438
>
> Review-Url: https://codereview.webrtc.org/2764573002
> Cr-Commit-Position: refs/heads/master@{#17527}
> Committed: https://chromium.googlesource.com/external/webrtc/+/e3aa88bbd5accadec73fa7e38584dfbf6aabe8a9
TBR=sakal@webrtc.org,mflodman@webrtc.org,stefan@webrtc.org,tommi@webrtc.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=webrtc:7361, 695438
Review-Url: https://codereview.webrtc.org/2792033003
Cr-Commit-Position: refs/heads/master@{#17530}
2017-04-04 07:16:21 -07:00
|
|
|
CheckOnCodecThread();
|
2016-03-04 14:10:50 -08:00
|
|
|
|
|
|
|
|
key_frame_required_ = true;
|
|
|
|
|
frames_received_ = 0;
|
|
|
|
|
frames_decoded_ = 0;
|
|
|
|
|
frames_decoded_logged_ = kMaxDecodedLogFrames;
|
2016-05-10 16:31:47 +02:00
|
|
|
start_time_ms_ = rtc::TimeMillis();
|
2016-03-04 14:10:50 -08:00
|
|
|
current_frames_ = 0;
|
|
|
|
|
current_bytes_ = 0;
|
|
|
|
|
current_decoding_time_ms_ = 0;
|
|
|
|
|
current_delay_time_ms_ = 0;
|
2017-02-17 03:26:10 -08:00
|
|
|
pending_frame_qps_.clear();
|
2016-03-04 14:10:50 -08:00
|
|
|
}
|
|
|
|
|
|
2015-02-18 18:42:55 +00:00
|
|
|
int32_t MediaCodecVideoDecoder::InitDecodeOnCodecThread() {
|
Revert of Deliver video frames on Android, on the decode thread. (patchset #7 id:120001 of https://codereview.webrtc.org/2764573002/ )
Reason for revert:
Breaks Chrome FYI Android bots.
See:
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus9%29/builds/20418
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus6%29/builds/14724
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus5%29/builds/20133
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28K%20Nexus5%29/builds/15111
Original issue's description:
> Deliver video frames on Android, on the decode thread.
>
> VideoCoding
> * Adding a method for polling for frames on Android only until the capture implementation takes care of this (longer term plan).
>
> CodecDatabase
> * Add an accessor for the current decoder
> * Use std::unique_ptr<> for ownership.
> * Remove "Release()" and "ReleaseDecoder()". Instead just delete.
> * Remove |friend| relationship between CodecDatabase and VCMGenericDecoder.
>
> VCMDecodedFrameCallback
> * DCHECKs for thread correctness.
> * Remove |lock_| now that a threading model has been established and verified.
>
> VCMGenericDecoder
> * All methods now have thread checks.
> * Variable access associated with thread checkers.
>
> VideoReceiver
> * Added two notification methods, DecoderThreadStarting() and DecoderThreadStopped()
> * Allows us to establish a period when the decoder thread is not running and it is safe to modify variables such as callbacks, that are only read when the decoder thread is running.
> * Allows us to DCHECK thread guarantees.
> * Allows synchronizing callbacks from the module process thread and have them only active while the decoder thread is running.
> * The above, allows us to establish two modes for the thread, single-threaded-mutable and multi-threaded-const.
> * Using that knowledge, we can remove |receive_crit_| as well as locking for a number of member variables.
>
> MediaCodecVideoDecoder
> * Removed frame polling code from this class, since this is now done from the root thread function in VideoReceiveStream.
>
> VideoReceiveStream
> * On Android: Polls for decoded frames every 10ms (same interval as previously in MediaCodecVideoDecoder)
> * [Un]Registers the |video_receiver_| with the module thread only around the time the decoder thread is started/stopped.
> * Notifies the receiver of start/stop events of the decoder thread.
> * Changed the decoder thread to use the new PlatformThread callback type.
>
> BUG=webrtc:7361, 695438
>
> Review-Url: https://codereview.webrtc.org/2764573002
> Cr-Commit-Position: refs/heads/master@{#17527}
> Committed: https://chromium.googlesource.com/external/webrtc/+/e3aa88bbd5accadec73fa7e38584dfbf6aabe8a9
TBR=sakal@webrtc.org,mflodman@webrtc.org,stefan@webrtc.org,tommi@webrtc.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=webrtc:7361, 695438
Review-Url: https://codereview.webrtc.org/2792033003
Cr-Commit-Position: refs/heads/master@{#17530}
2017-04-04 07:16:21 -07:00
|
|
|
CheckOnCodecThread();
|
2015-02-18 18:42:55 +00:00
|
|
|
JNIEnv* jni = AttachCurrentThreadIfNeeded();
|
|
|
|
|
ScopedLocalRefFrame local_ref_frame(jni);
|
2017-12-12 12:52:54 +01:00
|
|
|
ALOGD << "InitDecodeOnCodecThread Type: " << static_cast<int>(codecType_)
|
|
|
|
|
<< ". " << codec_.width << " x " << codec_.height
|
|
|
|
|
<< ". Fps: " << static_cast<int>(codec_.maxFramerate);
|
2015-06-12 16:40:44 -07:00
|
|
|
|
|
|
|
|
// Release previous codec first if it was allocated before.
|
|
|
|
|
int ret_val = ReleaseOnCodecThread();
|
|
|
|
|
if (ret_val < 0) {
|
2015-10-07 16:51:02 -07:00
|
|
|
ALOGE << "Release failure: " << ret_val << " - fallback to SW codec";
|
2015-06-12 16:40:44 -07:00
|
|
|
sw_fallback_required_ = true;
|
|
|
|
|
return WEBRTC_VIDEO_CODEC_ERROR;
|
2015-02-18 18:42:55 +00:00
|
|
|
}
|
|
|
|
|
|
2016-03-04 14:10:50 -08:00
|
|
|
ResetVariables();
|
2015-06-12 16:40:44 -07:00
|
|
|
|
2017-12-20 15:12:10 +01:00
|
|
|
ScopedJavaLocalRef<jobject> j_video_codec_enum =
|
2017-12-08 11:05:22 +01:00
|
|
|
Java_VideoCodecType_fromNativeIndex(jni, codecType_);
|
2018-04-23 11:29:05 +02:00
|
|
|
jobject j_egl_context = use_surface_ ? render_egl_context_ : nullptr;
|
2017-12-08 11:05:22 +01:00
|
|
|
bool success = Java_MediaCodecVideoDecoder_initDecode(
|
2017-12-20 15:12:10 +01:00
|
|
|
jni, j_media_codec_video_decoder_, j_video_codec_enum, codec_.width,
|
2018-04-23 11:29:05 +02:00
|
|
|
codec_.height, JavaParamRef<jobject>(j_egl_context));
|
2016-03-04 14:10:50 -08:00
|
|
|
|
2015-06-12 16:40:44 -07:00
|
|
|
if (CheckException(jni) || !success) {
|
2015-10-07 16:51:02 -07:00
|
|
|
ALOGE << "Codec initialization error - fallback to SW codec.";
|
2015-06-12 16:40:44 -07:00
|
|
|
sw_fallback_required_ = true;
|
2015-02-18 18:42:55 +00:00
|
|
|
return WEBRTC_VIDEO_CODEC_ERROR;
|
|
|
|
|
}
|
|
|
|
|
inited_ = true;
|
|
|
|
|
|
2015-02-25 00:02:50 +00:00
|
|
|
switch (codecType_) {
|
|
|
|
|
case kVideoCodecVP8:
|
|
|
|
|
max_pending_frames_ = kMaxPendingFramesVp8;
|
|
|
|
|
break;
|
2015-11-10 10:25:40 -08:00
|
|
|
case kVideoCodecVP9:
|
|
|
|
|
max_pending_frames_ = kMaxPendingFramesVp9;
|
|
|
|
|
break;
|
2015-02-25 00:02:50 +00:00
|
|
|
case kVideoCodecH264:
|
|
|
|
|
max_pending_frames_ = kMaxPendingFramesH264;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
max_pending_frames_ = 0;
|
2015-02-18 18:42:55 +00:00
|
|
|
}
|
2016-03-04 14:10:50 -08:00
|
|
|
ALOGD << "Maximum amount of pending frames: " << max_pending_frames_;
|
2015-02-18 18:42:55 +00:00
|
|
|
|
2017-12-20 15:12:10 +01:00
|
|
|
ScopedJavaLocalRef<jobjectArray> input_buffers =
|
|
|
|
|
Java_MediaCodecVideoDecoder_getInputBuffers(jni,
|
|
|
|
|
j_media_codec_video_decoder_);
|
|
|
|
|
input_buffers_ = JavaToNativeVector<ScopedJavaGlobalRef<jobject>>(
|
|
|
|
|
jni, input_buffers, [](JNIEnv* env, const JavaRef<jobject>& o) {
|
|
|
|
|
return ScopedJavaGlobalRef<jobject>(env, o);
|
|
|
|
|
});
|
2015-02-18 18:42:55 +00:00
|
|
|
|
Revert of Deliver video frames on Android, on the decode thread. (patchset #7 id:120001 of https://codereview.webrtc.org/2764573002/ )
Reason for revert:
Breaks Chrome FYI Android bots.
See:
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus9%29/builds/20418
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus6%29/builds/14724
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus5%29/builds/20133
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28K%20Nexus5%29/builds/15111
Original issue's description:
> Deliver video frames on Android, on the decode thread.
>
> VideoCoding
> * Adding a method for polling for frames on Android only until the capture implementation takes care of this (longer term plan).
>
> CodecDatabase
> * Add an accessor for the current decoder
> * Use std::unique_ptr<> for ownership.
> * Remove "Release()" and "ReleaseDecoder()". Instead just delete.
> * Remove |friend| relationship between CodecDatabase and VCMGenericDecoder.
>
> VCMDecodedFrameCallback
> * DCHECKs for thread correctness.
> * Remove |lock_| now that a threading model has been established and verified.
>
> VCMGenericDecoder
> * All methods now have thread checks.
> * Variable access associated with thread checkers.
>
> VideoReceiver
> * Added two notification methods, DecoderThreadStarting() and DecoderThreadStopped()
> * Allows us to establish a period when the decoder thread is not running and it is safe to modify variables such as callbacks, that are only read when the decoder thread is running.
> * Allows us to DCHECK thread guarantees.
> * Allows synchronizing callbacks from the module process thread and have them only active while the decoder thread is running.
> * The above, allows us to establish two modes for the thread, single-threaded-mutable and multi-threaded-const.
> * Using that knowledge, we can remove |receive_crit_| as well as locking for a number of member variables.
>
> MediaCodecVideoDecoder
> * Removed frame polling code from this class, since this is now done from the root thread function in VideoReceiveStream.
>
> VideoReceiveStream
> * On Android: Polls for decoded frames every 10ms (same interval as previously in MediaCodecVideoDecoder)
> * [Un]Registers the |video_receiver_| with the module thread only around the time the decoder thread is started/stopped.
> * Notifies the receiver of start/stop events of the decoder thread.
> * Changed the decoder thread to use the new PlatformThread callback type.
>
> BUG=webrtc:7361, 695438
>
> Review-Url: https://codereview.webrtc.org/2764573002
> Cr-Commit-Position: refs/heads/master@{#17527}
> Committed: https://chromium.googlesource.com/external/webrtc/+/e3aa88bbd5accadec73fa7e38584dfbf6aabe8a9
TBR=sakal@webrtc.org,mflodman@webrtc.org,stefan@webrtc.org,tommi@webrtc.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=webrtc:7361, 695438
Review-Url: https://codereview.webrtc.org/2792033003
Cr-Commit-Position: refs/heads/master@{#17530}
2017-04-04 07:16:21 -07:00
|
|
|
codec_thread_->PostDelayed(RTC_FROM_HERE, kMediaCodecPollMs, this);
|
|
|
|
|
|
2015-02-18 18:42:55 +00:00
|
|
|
return WEBRTC_VIDEO_CODEC_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-04 14:10:50 -08:00
|
|
|
int32_t MediaCodecVideoDecoder::ResetDecodeOnCodecThread() {
|
Revert of Deliver video frames on Android, on the decode thread. (patchset #7 id:120001 of https://codereview.webrtc.org/2764573002/ )
Reason for revert:
Breaks Chrome FYI Android bots.
See:
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus9%29/builds/20418
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus6%29/builds/14724
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus5%29/builds/20133
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28K%20Nexus5%29/builds/15111
Original issue's description:
> Deliver video frames on Android, on the decode thread.
>
> VideoCoding
> * Adding a method for polling for frames on Android only until the capture implementation takes care of this (longer term plan).
>
> CodecDatabase
> * Add an accessor for the current decoder
> * Use std::unique_ptr<> for ownership.
> * Remove "Release()" and "ReleaseDecoder()". Instead just delete.
> * Remove |friend| relationship between CodecDatabase and VCMGenericDecoder.
>
> VCMDecodedFrameCallback
> * DCHECKs for thread correctness.
> * Remove |lock_| now that a threading model has been established and verified.
>
> VCMGenericDecoder
> * All methods now have thread checks.
> * Variable access associated with thread checkers.
>
> VideoReceiver
> * Added two notification methods, DecoderThreadStarting() and DecoderThreadStopped()
> * Allows us to establish a period when the decoder thread is not running and it is safe to modify variables such as callbacks, that are only read when the decoder thread is running.
> * Allows us to DCHECK thread guarantees.
> * Allows synchronizing callbacks from the module process thread and have them only active while the decoder thread is running.
> * The above, allows us to establish two modes for the thread, single-threaded-mutable and multi-threaded-const.
> * Using that knowledge, we can remove |receive_crit_| as well as locking for a number of member variables.
>
> MediaCodecVideoDecoder
> * Removed frame polling code from this class, since this is now done from the root thread function in VideoReceiveStream.
>
> VideoReceiveStream
> * On Android: Polls for decoded frames every 10ms (same interval as previously in MediaCodecVideoDecoder)
> * [Un]Registers the |video_receiver_| with the module thread only around the time the decoder thread is started/stopped.
> * Notifies the receiver of start/stop events of the decoder thread.
> * Changed the decoder thread to use the new PlatformThread callback type.
>
> BUG=webrtc:7361, 695438
>
> Review-Url: https://codereview.webrtc.org/2764573002
> Cr-Commit-Position: refs/heads/master@{#17527}
> Committed: https://chromium.googlesource.com/external/webrtc/+/e3aa88bbd5accadec73fa7e38584dfbf6aabe8a9
TBR=sakal@webrtc.org,mflodman@webrtc.org,stefan@webrtc.org,tommi@webrtc.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=webrtc:7361, 695438
Review-Url: https://codereview.webrtc.org/2792033003
Cr-Commit-Position: refs/heads/master@{#17530}
2017-04-04 07:16:21 -07:00
|
|
|
CheckOnCodecThread();
|
2016-03-04 14:10:50 -08:00
|
|
|
JNIEnv* jni = AttachCurrentThreadIfNeeded();
|
|
|
|
|
ScopedLocalRefFrame local_ref_frame(jni);
|
2017-12-12 12:52:54 +01:00
|
|
|
ALOGD << "ResetDecodeOnCodecThread Type: " << static_cast<int>(codecType_)
|
|
|
|
|
<< ". " << codec_.width << " x " << codec_.height;
|
2016-03-04 14:10:50 -08:00
|
|
|
ALOGD << " Frames received: " << frames_received_
|
|
|
|
|
<< ". Frames decoded: " << frames_decoded_;
|
|
|
|
|
|
|
|
|
|
inited_ = false;
|
Revert of Deliver video frames on Android, on the decode thread. (patchset #7 id:120001 of https://codereview.webrtc.org/2764573002/ )
Reason for revert:
Breaks Chrome FYI Android bots.
See:
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus9%29/builds/20418
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus6%29/builds/14724
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus5%29/builds/20133
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28K%20Nexus5%29/builds/15111
Original issue's description:
> Deliver video frames on Android, on the decode thread.
>
> VideoCoding
> * Adding a method for polling for frames on Android only until the capture implementation takes care of this (longer term plan).
>
> CodecDatabase
> * Add an accessor for the current decoder
> * Use std::unique_ptr<> for ownership.
> * Remove "Release()" and "ReleaseDecoder()". Instead just delete.
> * Remove |friend| relationship between CodecDatabase and VCMGenericDecoder.
>
> VCMDecodedFrameCallback
> * DCHECKs for thread correctness.
> * Remove |lock_| now that a threading model has been established and verified.
>
> VCMGenericDecoder
> * All methods now have thread checks.
> * Variable access associated with thread checkers.
>
> VideoReceiver
> * Added two notification methods, DecoderThreadStarting() and DecoderThreadStopped()
> * Allows us to establish a period when the decoder thread is not running and it is safe to modify variables such as callbacks, that are only read when the decoder thread is running.
> * Allows us to DCHECK thread guarantees.
> * Allows synchronizing callbacks from the module process thread and have them only active while the decoder thread is running.
> * The above, allows us to establish two modes for the thread, single-threaded-mutable and multi-threaded-const.
> * Using that knowledge, we can remove |receive_crit_| as well as locking for a number of member variables.
>
> MediaCodecVideoDecoder
> * Removed frame polling code from this class, since this is now done from the root thread function in VideoReceiveStream.
>
> VideoReceiveStream
> * On Android: Polls for decoded frames every 10ms (same interval as previously in MediaCodecVideoDecoder)
> * [Un]Registers the |video_receiver_| with the module thread only around the time the decoder thread is started/stopped.
> * Notifies the receiver of start/stop events of the decoder thread.
> * Changed the decoder thread to use the new PlatformThread callback type.
>
> BUG=webrtc:7361, 695438
>
> Review-Url: https://codereview.webrtc.org/2764573002
> Cr-Commit-Position: refs/heads/master@{#17527}
> Committed: https://chromium.googlesource.com/external/webrtc/+/e3aa88bbd5accadec73fa7e38584dfbf6aabe8a9
TBR=sakal@webrtc.org,mflodman@webrtc.org,stefan@webrtc.org,tommi@webrtc.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=webrtc:7361, 695438
Review-Url: https://codereview.webrtc.org/2792033003
Cr-Commit-Position: refs/heads/master@{#17530}
2017-04-04 07:16:21 -07:00
|
|
|
rtc::MessageQueueManager::Clear(this);
|
2016-03-04 14:10:50 -08:00
|
|
|
ResetVariables();
|
|
|
|
|
|
2017-12-20 15:12:10 +01:00
|
|
|
Java_MediaCodecVideoDecoder_reset(jni, j_media_codec_video_decoder_,
|
2017-12-08 11:05:22 +01:00
|
|
|
codec_.width, codec_.height);
|
2016-03-04 14:10:50 -08:00
|
|
|
|
|
|
|
|
if (CheckException(jni)) {
|
|
|
|
|
ALOGE << "Soft reset error - fallback to SW codec.";
|
|
|
|
|
sw_fallback_required_ = true;
|
|
|
|
|
return WEBRTC_VIDEO_CODEC_ERROR;
|
|
|
|
|
}
|
|
|
|
|
inited_ = true;
|
|
|
|
|
|
Revert of Deliver video frames on Android, on the decode thread. (patchset #7 id:120001 of https://codereview.webrtc.org/2764573002/ )
Reason for revert:
Breaks Chrome FYI Android bots.
See:
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus9%29/builds/20418
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus6%29/builds/14724
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus5%29/builds/20133
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28K%20Nexus5%29/builds/15111
Original issue's description:
> Deliver video frames on Android, on the decode thread.
>
> VideoCoding
> * Adding a method for polling for frames on Android only until the capture implementation takes care of this (longer term plan).
>
> CodecDatabase
> * Add an accessor for the current decoder
> * Use std::unique_ptr<> for ownership.
> * Remove "Release()" and "ReleaseDecoder()". Instead just delete.
> * Remove |friend| relationship between CodecDatabase and VCMGenericDecoder.
>
> VCMDecodedFrameCallback
> * DCHECKs for thread correctness.
> * Remove |lock_| now that a threading model has been established and verified.
>
> VCMGenericDecoder
> * All methods now have thread checks.
> * Variable access associated with thread checkers.
>
> VideoReceiver
> * Added two notification methods, DecoderThreadStarting() and DecoderThreadStopped()
> * Allows us to establish a period when the decoder thread is not running and it is safe to modify variables such as callbacks, that are only read when the decoder thread is running.
> * Allows us to DCHECK thread guarantees.
> * Allows synchronizing callbacks from the module process thread and have them only active while the decoder thread is running.
> * The above, allows us to establish two modes for the thread, single-threaded-mutable and multi-threaded-const.
> * Using that knowledge, we can remove |receive_crit_| as well as locking for a number of member variables.
>
> MediaCodecVideoDecoder
> * Removed frame polling code from this class, since this is now done from the root thread function in VideoReceiveStream.
>
> VideoReceiveStream
> * On Android: Polls for decoded frames every 10ms (same interval as previously in MediaCodecVideoDecoder)
> * [Un]Registers the |video_receiver_| with the module thread only around the time the decoder thread is started/stopped.
> * Notifies the receiver of start/stop events of the decoder thread.
> * Changed the decoder thread to use the new PlatformThread callback type.
>
> BUG=webrtc:7361, 695438
>
> Review-Url: https://codereview.webrtc.org/2764573002
> Cr-Commit-Position: refs/heads/master@{#17527}
> Committed: https://chromium.googlesource.com/external/webrtc/+/e3aa88bbd5accadec73fa7e38584dfbf6aabe8a9
TBR=sakal@webrtc.org,mflodman@webrtc.org,stefan@webrtc.org,tommi@webrtc.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=webrtc:7361, 695438
Review-Url: https://codereview.webrtc.org/2792033003
Cr-Commit-Position: refs/heads/master@{#17530}
2017-04-04 07:16:21 -07:00
|
|
|
codec_thread_->PostDelayed(RTC_FROM_HERE, kMediaCodecPollMs, this);
|
|
|
|
|
|
2016-03-04 14:10:50 -08:00
|
|
|
return WEBRTC_VIDEO_CODEC_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-18 18:42:55 +00:00
|
|
|
int32_t MediaCodecVideoDecoder::Release() {
|
2015-10-07 16:51:02 -07:00
|
|
|
ALOGD << "DecoderRelease request";
|
2015-02-18 18:42:55 +00:00
|
|
|
return codec_thread_->Invoke<int32_t>(
|
2016-06-10 14:17:27 -07:00
|
|
|
RTC_FROM_HERE, Bind(&MediaCodecVideoDecoder::ReleaseOnCodecThread, this));
|
2015-02-18 18:42:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int32_t MediaCodecVideoDecoder::ReleaseOnCodecThread() {
|
|
|
|
|
if (!inited_) {
|
|
|
|
|
return WEBRTC_VIDEO_CODEC_OK;
|
|
|
|
|
}
|
Revert of Deliver video frames on Android, on the decode thread. (patchset #7 id:120001 of https://codereview.webrtc.org/2764573002/ )
Reason for revert:
Breaks Chrome FYI Android bots.
See:
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus9%29/builds/20418
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus6%29/builds/14724
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus5%29/builds/20133
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28K%20Nexus5%29/builds/15111
Original issue's description:
> Deliver video frames on Android, on the decode thread.
>
> VideoCoding
> * Adding a method for polling for frames on Android only until the capture implementation takes care of this (longer term plan).
>
> CodecDatabase
> * Add an accessor for the current decoder
> * Use std::unique_ptr<> for ownership.
> * Remove "Release()" and "ReleaseDecoder()". Instead just delete.
> * Remove |friend| relationship between CodecDatabase and VCMGenericDecoder.
>
> VCMDecodedFrameCallback
> * DCHECKs for thread correctness.
> * Remove |lock_| now that a threading model has been established and verified.
>
> VCMGenericDecoder
> * All methods now have thread checks.
> * Variable access associated with thread checkers.
>
> VideoReceiver
> * Added two notification methods, DecoderThreadStarting() and DecoderThreadStopped()
> * Allows us to establish a period when the decoder thread is not running and it is safe to modify variables such as callbacks, that are only read when the decoder thread is running.
> * Allows us to DCHECK thread guarantees.
> * Allows synchronizing callbacks from the module process thread and have them only active while the decoder thread is running.
> * The above, allows us to establish two modes for the thread, single-threaded-mutable and multi-threaded-const.
> * Using that knowledge, we can remove |receive_crit_| as well as locking for a number of member variables.
>
> MediaCodecVideoDecoder
> * Removed frame polling code from this class, since this is now done from the root thread function in VideoReceiveStream.
>
> VideoReceiveStream
> * On Android: Polls for decoded frames every 10ms (same interval as previously in MediaCodecVideoDecoder)
> * [Un]Registers the |video_receiver_| with the module thread only around the time the decoder thread is started/stopped.
> * Notifies the receiver of start/stop events of the decoder thread.
> * Changed the decoder thread to use the new PlatformThread callback type.
>
> BUG=webrtc:7361, 695438
>
> Review-Url: https://codereview.webrtc.org/2764573002
> Cr-Commit-Position: refs/heads/master@{#17527}
> Committed: https://chromium.googlesource.com/external/webrtc/+/e3aa88bbd5accadec73fa7e38584dfbf6aabe8a9
TBR=sakal@webrtc.org,mflodman@webrtc.org,stefan@webrtc.org,tommi@webrtc.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=webrtc:7361, 695438
Review-Url: https://codereview.webrtc.org/2792033003
Cr-Commit-Position: refs/heads/master@{#17530}
2017-04-04 07:16:21 -07:00
|
|
|
CheckOnCodecThread();
|
2015-02-18 18:42:55 +00:00
|
|
|
JNIEnv* jni = AttachCurrentThreadIfNeeded();
|
2015-10-28 10:30:32 -07:00
|
|
|
ALOGD << "DecoderReleaseOnCodecThread: Frames received: " << frames_received_
|
|
|
|
|
<< ". Frames decoded: " << frames_decoded_;
|
2015-02-18 18:42:55 +00:00
|
|
|
ScopedLocalRefFrame local_ref_frame(jni);
|
|
|
|
|
input_buffers_.clear();
|
2017-12-20 15:12:10 +01:00
|
|
|
Java_MediaCodecVideoDecoder_release(jni, j_media_codec_video_decoder_);
|
2015-02-18 18:42:55 +00:00
|
|
|
inited_ = false;
|
Revert of Deliver video frames on Android, on the decode thread. (patchset #7 id:120001 of https://codereview.webrtc.org/2764573002/ )
Reason for revert:
Breaks Chrome FYI Android bots.
See:
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus9%29/builds/20418
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus6%29/builds/14724
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus5%29/builds/20133
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28K%20Nexus5%29/builds/15111
Original issue's description:
> Deliver video frames on Android, on the decode thread.
>
> VideoCoding
> * Adding a method for polling for frames on Android only until the capture implementation takes care of this (longer term plan).
>
> CodecDatabase
> * Add an accessor for the current decoder
> * Use std::unique_ptr<> for ownership.
> * Remove "Release()" and "ReleaseDecoder()". Instead just delete.
> * Remove |friend| relationship between CodecDatabase and VCMGenericDecoder.
>
> VCMDecodedFrameCallback
> * DCHECKs for thread correctness.
> * Remove |lock_| now that a threading model has been established and verified.
>
> VCMGenericDecoder
> * All methods now have thread checks.
> * Variable access associated with thread checkers.
>
> VideoReceiver
> * Added two notification methods, DecoderThreadStarting() and DecoderThreadStopped()
> * Allows us to establish a period when the decoder thread is not running and it is safe to modify variables such as callbacks, that are only read when the decoder thread is running.
> * Allows us to DCHECK thread guarantees.
> * Allows synchronizing callbacks from the module process thread and have them only active while the decoder thread is running.
> * The above, allows us to establish two modes for the thread, single-threaded-mutable and multi-threaded-const.
> * Using that knowledge, we can remove |receive_crit_| as well as locking for a number of member variables.
>
> MediaCodecVideoDecoder
> * Removed frame polling code from this class, since this is now done from the root thread function in VideoReceiveStream.
>
> VideoReceiveStream
> * On Android: Polls for decoded frames every 10ms (same interval as previously in MediaCodecVideoDecoder)
> * [Un]Registers the |video_receiver_| with the module thread only around the time the decoder thread is started/stopped.
> * Notifies the receiver of start/stop events of the decoder thread.
> * Changed the decoder thread to use the new PlatformThread callback type.
>
> BUG=webrtc:7361, 695438
>
> Review-Url: https://codereview.webrtc.org/2764573002
> Cr-Commit-Position: refs/heads/master@{#17527}
> Committed: https://chromium.googlesource.com/external/webrtc/+/e3aa88bbd5accadec73fa7e38584dfbf6aabe8a9
TBR=sakal@webrtc.org,mflodman@webrtc.org,stefan@webrtc.org,tommi@webrtc.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=webrtc:7361, 695438
Review-Url: https://codereview.webrtc.org/2792033003
Cr-Commit-Position: refs/heads/master@{#17530}
2017-04-04 07:16:21 -07:00
|
|
|
rtc::MessageQueueManager::Clear(this);
|
2015-06-12 16:40:44 -07:00
|
|
|
if (CheckException(jni)) {
|
2015-10-07 16:51:02 -07:00
|
|
|
ALOGE << "Decoder release exception";
|
2015-06-12 16:40:44 -07:00
|
|
|
return WEBRTC_VIDEO_CODEC_ERROR;
|
|
|
|
|
}
|
2015-10-07 16:51:02 -07:00
|
|
|
ALOGD << "DecoderReleaseOnCodecThread done";
|
2015-02-18 18:42:55 +00:00
|
|
|
return WEBRTC_VIDEO_CODEC_OK;
|
|
|
|
|
}
|
|
|
|
|
|
Revert of Deliver video frames on Android, on the decode thread. (patchset #7 id:120001 of https://codereview.webrtc.org/2764573002/ )
Reason for revert:
Breaks Chrome FYI Android bots.
See:
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus9%29/builds/20418
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus6%29/builds/14724
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus5%29/builds/20133
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28K%20Nexus5%29/builds/15111
Original issue's description:
> Deliver video frames on Android, on the decode thread.
>
> VideoCoding
> * Adding a method for polling for frames on Android only until the capture implementation takes care of this (longer term plan).
>
> CodecDatabase
> * Add an accessor for the current decoder
> * Use std::unique_ptr<> for ownership.
> * Remove "Release()" and "ReleaseDecoder()". Instead just delete.
> * Remove |friend| relationship between CodecDatabase and VCMGenericDecoder.
>
> VCMDecodedFrameCallback
> * DCHECKs for thread correctness.
> * Remove |lock_| now that a threading model has been established and verified.
>
> VCMGenericDecoder
> * All methods now have thread checks.
> * Variable access associated with thread checkers.
>
> VideoReceiver
> * Added two notification methods, DecoderThreadStarting() and DecoderThreadStopped()
> * Allows us to establish a period when the decoder thread is not running and it is safe to modify variables such as callbacks, that are only read when the decoder thread is running.
> * Allows us to DCHECK thread guarantees.
> * Allows synchronizing callbacks from the module process thread and have them only active while the decoder thread is running.
> * The above, allows us to establish two modes for the thread, single-threaded-mutable and multi-threaded-const.
> * Using that knowledge, we can remove |receive_crit_| as well as locking for a number of member variables.
>
> MediaCodecVideoDecoder
> * Removed frame polling code from this class, since this is now done from the root thread function in VideoReceiveStream.
>
> VideoReceiveStream
> * On Android: Polls for decoded frames every 10ms (same interval as previously in MediaCodecVideoDecoder)
> * [Un]Registers the |video_receiver_| with the module thread only around the time the decoder thread is started/stopped.
> * Notifies the receiver of start/stop events of the decoder thread.
> * Changed the decoder thread to use the new PlatformThread callback type.
>
> BUG=webrtc:7361, 695438
>
> Review-Url: https://codereview.webrtc.org/2764573002
> Cr-Commit-Position: refs/heads/master@{#17527}
> Committed: https://chromium.googlesource.com/external/webrtc/+/e3aa88bbd5accadec73fa7e38584dfbf6aabe8a9
TBR=sakal@webrtc.org,mflodman@webrtc.org,stefan@webrtc.org,tommi@webrtc.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=webrtc:7361, 695438
Review-Url: https://codereview.webrtc.org/2792033003
Cr-Commit-Position: refs/heads/master@{#17530}
2017-04-04 07:16:21 -07:00
|
|
|
void MediaCodecVideoDecoder::CheckOnCodecThread() {
|
|
|
|
|
RTC_CHECK(codec_thread_.get() == ThreadManager::Instance()->CurrentThread())
|
|
|
|
|
<< "Running on wrong thread!";
|
2015-02-18 18:42:55 +00:00
|
|
|
}
|
|
|
|
|
|
2016-02-04 11:47:12 -08:00
|
|
|
void MediaCodecVideoDecoder::EnableFrameLogOnWarning() {
|
|
|
|
|
// Log next 2 output frames.
|
|
|
|
|
frames_decoded_logged_ =
|
|
|
|
|
std::max(frames_decoded_logged_, frames_decoded_ + kMaxWarningLogFrames);
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-12 16:40:44 -07:00
|
|
|
int32_t MediaCodecVideoDecoder::ProcessHWErrorOnCodecThread() {
|
Revert of Deliver video frames on Android, on the decode thread. (patchset #7 id:120001 of https://codereview.webrtc.org/2764573002/ )
Reason for revert:
Breaks Chrome FYI Android bots.
See:
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus9%29/builds/20418
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus6%29/builds/14724
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus5%29/builds/20133
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28K%20Nexus5%29/builds/15111
Original issue's description:
> Deliver video frames on Android, on the decode thread.
>
> VideoCoding
> * Adding a method for polling for frames on Android only until the capture implementation takes care of this (longer term plan).
>
> CodecDatabase
> * Add an accessor for the current decoder
> * Use std::unique_ptr<> for ownership.
> * Remove "Release()" and "ReleaseDecoder()". Instead just delete.
> * Remove |friend| relationship between CodecDatabase and VCMGenericDecoder.
>
> VCMDecodedFrameCallback
> * DCHECKs for thread correctness.
> * Remove |lock_| now that a threading model has been established and verified.
>
> VCMGenericDecoder
> * All methods now have thread checks.
> * Variable access associated with thread checkers.
>
> VideoReceiver
> * Added two notification methods, DecoderThreadStarting() and DecoderThreadStopped()
> * Allows us to establish a period when the decoder thread is not running and it is safe to modify variables such as callbacks, that are only read when the decoder thread is running.
> * Allows us to DCHECK thread guarantees.
> * Allows synchronizing callbacks from the module process thread and have them only active while the decoder thread is running.
> * The above, allows us to establish two modes for the thread, single-threaded-mutable and multi-threaded-const.
> * Using that knowledge, we can remove |receive_crit_| as well as locking for a number of member variables.
>
> MediaCodecVideoDecoder
> * Removed frame polling code from this class, since this is now done from the root thread function in VideoReceiveStream.
>
> VideoReceiveStream
> * On Android: Polls for decoded frames every 10ms (same interval as previously in MediaCodecVideoDecoder)
> * [Un]Registers the |video_receiver_| with the module thread only around the time the decoder thread is started/stopped.
> * Notifies the receiver of start/stop events of the decoder thread.
> * Changed the decoder thread to use the new PlatformThread callback type.
>
> BUG=webrtc:7361, 695438
>
> Review-Url: https://codereview.webrtc.org/2764573002
> Cr-Commit-Position: refs/heads/master@{#17527}
> Committed: https://chromium.googlesource.com/external/webrtc/+/e3aa88bbd5accadec73fa7e38584dfbf6aabe8a9
TBR=sakal@webrtc.org,mflodman@webrtc.org,stefan@webrtc.org,tommi@webrtc.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=webrtc:7361, 695438
Review-Url: https://codereview.webrtc.org/2792033003
Cr-Commit-Position: refs/heads/master@{#17530}
2017-04-04 07:16:21 -07:00
|
|
|
CheckOnCodecThread();
|
2015-06-12 16:40:44 -07:00
|
|
|
int ret_val = ReleaseOnCodecThread();
|
|
|
|
|
if (ret_val < 0) {
|
2015-10-07 16:51:02 -07:00
|
|
|
ALOGE << "ProcessHWError: Release failure";
|
2015-06-12 16:40:44 -07:00
|
|
|
}
|
|
|
|
|
if (codecType_ == kVideoCodecH264) {
|
|
|
|
|
// For now there is no SW H.264 which can be used as fallback codec.
|
|
|
|
|
// So try to restart hw codec for now.
|
|
|
|
|
ret_val = InitDecodeOnCodecThread();
|
2015-10-07 16:51:02 -07:00
|
|
|
ALOGE << "Reset H.264 codec done. Status: " << ret_val;
|
2015-06-12 16:40:44 -07:00
|
|
|
if (ret_val == WEBRTC_VIDEO_CODEC_OK) {
|
|
|
|
|
// H.264 codec was succesfully reset - return regular error code.
|
|
|
|
|
return WEBRTC_VIDEO_CODEC_ERROR;
|
|
|
|
|
} else {
|
|
|
|
|
// Fail to restart H.264 codec - return error code which should stop the
|
|
|
|
|
// call.
|
|
|
|
|
return WEBRTC_VIDEO_CODEC_FALLBACK_SOFTWARE;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
sw_fallback_required_ = true;
|
2015-10-07 16:51:02 -07:00
|
|
|
ALOGE << "Return WEBRTC_VIDEO_CODEC_FALLBACK_SOFTWARE";
|
2015-06-12 16:40:44 -07:00
|
|
|
return WEBRTC_VIDEO_CODEC_FALLBACK_SOFTWARE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-18 18:42:55 +00:00
|
|
|
int32_t MediaCodecVideoDecoder::Decode(
|
|
|
|
|
const EncodedImage& inputImage,
|
|
|
|
|
bool missingFrames,
|
|
|
|
|
const CodecSpecificInfo* codecSpecificInfo,
|
|
|
|
|
int64_t renderTimeMs) {
|
2015-06-12 16:40:44 -07:00
|
|
|
if (sw_fallback_required_) {
|
2015-10-07 16:51:02 -07:00
|
|
|
ALOGE << "Decode() - fallback to SW codec";
|
2015-06-12 16:40:44 -07:00
|
|
|
return WEBRTC_VIDEO_CODEC_FALLBACK_SOFTWARE;
|
2015-02-18 18:42:55 +00:00
|
|
|
}
|
Revert of Deliver video frames on Android, on the decode thread. (patchset #7 id:120001 of https://codereview.webrtc.org/2764573002/ )
Reason for revert:
Breaks Chrome FYI Android bots.
See:
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus9%29/builds/20418
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus6%29/builds/14724
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus5%29/builds/20133
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28K%20Nexus5%29/builds/15111
Original issue's description:
> Deliver video frames on Android, on the decode thread.
>
> VideoCoding
> * Adding a method for polling for frames on Android only until the capture implementation takes care of this (longer term plan).
>
> CodecDatabase
> * Add an accessor for the current decoder
> * Use std::unique_ptr<> for ownership.
> * Remove "Release()" and "ReleaseDecoder()". Instead just delete.
> * Remove |friend| relationship between CodecDatabase and VCMGenericDecoder.
>
> VCMDecodedFrameCallback
> * DCHECKs for thread correctness.
> * Remove |lock_| now that a threading model has been established and verified.
>
> VCMGenericDecoder
> * All methods now have thread checks.
> * Variable access associated with thread checkers.
>
> VideoReceiver
> * Added two notification methods, DecoderThreadStarting() and DecoderThreadStopped()
> * Allows us to establish a period when the decoder thread is not running and it is safe to modify variables such as callbacks, that are only read when the decoder thread is running.
> * Allows us to DCHECK thread guarantees.
> * Allows synchronizing callbacks from the module process thread and have them only active while the decoder thread is running.
> * The above, allows us to establish two modes for the thread, single-threaded-mutable and multi-threaded-const.
> * Using that knowledge, we can remove |receive_crit_| as well as locking for a number of member variables.
>
> MediaCodecVideoDecoder
> * Removed frame polling code from this class, since this is now done from the root thread function in VideoReceiveStream.
>
> VideoReceiveStream
> * On Android: Polls for decoded frames every 10ms (same interval as previously in MediaCodecVideoDecoder)
> * [Un]Registers the |video_receiver_| with the module thread only around the time the decoder thread is started/stopped.
> * Notifies the receiver of start/stop events of the decoder thread.
> * Changed the decoder thread to use the new PlatformThread callback type.
>
> BUG=webrtc:7361, 695438
>
> Review-Url: https://codereview.webrtc.org/2764573002
> Cr-Commit-Position: refs/heads/master@{#17527}
> Committed: https://chromium.googlesource.com/external/webrtc/+/e3aa88bbd5accadec73fa7e38584dfbf6aabe8a9
TBR=sakal@webrtc.org,mflodman@webrtc.org,stefan@webrtc.org,tommi@webrtc.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=webrtc:7361, 695438
Review-Url: https://codereview.webrtc.org/2792033003
Cr-Commit-Position: refs/heads/master@{#17530}
2017-04-04 07:16:21 -07:00
|
|
|
if (callback_ == NULL) {
|
|
|
|
|
ALOGE << "Decode() - callback_ is NULL";
|
|
|
|
|
return WEBRTC_VIDEO_CODEC_UNINITIALIZED;
|
|
|
|
|
}
|
2015-02-18 18:42:55 +00:00
|
|
|
if (inputImage._buffer == NULL && inputImage._length > 0) {
|
2015-10-07 16:51:02 -07:00
|
|
|
ALOGE << "Decode() - inputImage is incorrect";
|
2015-02-18 18:42:55 +00:00
|
|
|
return WEBRTC_VIDEO_CODEC_ERR_PARAMETER;
|
|
|
|
|
}
|
Revert of Deliver video frames on Android, on the decode thread. (patchset #7 id:120001 of https://codereview.webrtc.org/2764573002/ )
Reason for revert:
Breaks Chrome FYI Android bots.
See:
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus9%29/builds/20418
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus6%29/builds/14724
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus5%29/builds/20133
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28K%20Nexus5%29/builds/15111
Original issue's description:
> Deliver video frames on Android, on the decode thread.
>
> VideoCoding
> * Adding a method for polling for frames on Android only until the capture implementation takes care of this (longer term plan).
>
> CodecDatabase
> * Add an accessor for the current decoder
> * Use std::unique_ptr<> for ownership.
> * Remove "Release()" and "ReleaseDecoder()". Instead just delete.
> * Remove |friend| relationship between CodecDatabase and VCMGenericDecoder.
>
> VCMDecodedFrameCallback
> * DCHECKs for thread correctness.
> * Remove |lock_| now that a threading model has been established and verified.
>
> VCMGenericDecoder
> * All methods now have thread checks.
> * Variable access associated with thread checkers.
>
> VideoReceiver
> * Added two notification methods, DecoderThreadStarting() and DecoderThreadStopped()
> * Allows us to establish a period when the decoder thread is not running and it is safe to modify variables such as callbacks, that are only read when the decoder thread is running.
> * Allows us to DCHECK thread guarantees.
> * Allows synchronizing callbacks from the module process thread and have them only active while the decoder thread is running.
> * The above, allows us to establish two modes for the thread, single-threaded-mutable and multi-threaded-const.
> * Using that knowledge, we can remove |receive_crit_| as well as locking for a number of member variables.
>
> MediaCodecVideoDecoder
> * Removed frame polling code from this class, since this is now done from the root thread function in VideoReceiveStream.
>
> VideoReceiveStream
> * On Android: Polls for decoded frames every 10ms (same interval as previously in MediaCodecVideoDecoder)
> * [Un]Registers the |video_receiver_| with the module thread only around the time the decoder thread is started/stopped.
> * Notifies the receiver of start/stop events of the decoder thread.
> * Changed the decoder thread to use the new PlatformThread callback type.
>
> BUG=webrtc:7361, 695438
>
> Review-Url: https://codereview.webrtc.org/2764573002
> Cr-Commit-Position: refs/heads/master@{#17527}
> Committed: https://chromium.googlesource.com/external/webrtc/+/e3aa88bbd5accadec73fa7e38584dfbf6aabe8a9
TBR=sakal@webrtc.org,mflodman@webrtc.org,stefan@webrtc.org,tommi@webrtc.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=webrtc:7361, 695438
Review-Url: https://codereview.webrtc.org/2792033003
Cr-Commit-Position: refs/heads/master@{#17530}
2017-04-04 07:16:21 -07:00
|
|
|
if (!inited_) {
|
|
|
|
|
ALOGE << "Decode() - decoder is not initialized";
|
|
|
|
|
return WEBRTC_VIDEO_CODEC_UNINITIALIZED;
|
|
|
|
|
}
|
2015-06-12 16:40:44 -07:00
|
|
|
|
2015-02-18 18:42:55 +00:00
|
|
|
// Check if encoded frame dimension has changed.
|
|
|
|
|
if ((inputImage._encodedWidth * inputImage._encodedHeight > 0) &&
|
2018-06-08 11:04:04 +00:00
|
|
|
(inputImage._encodedWidth != codec_.width ||
|
|
|
|
|
inputImage._encodedHeight != codec_.height)) {
|
2016-03-04 14:10:50 -08:00
|
|
|
ALOGW << "Input resolution changed from " << codec_.width << " x "
|
|
|
|
|
<< codec_.height << " to " << inputImage._encodedWidth << " x "
|
|
|
|
|
<< inputImage._encodedHeight;
|
2015-02-18 18:42:55 +00:00
|
|
|
codec_.width = inputImage._encodedWidth;
|
|
|
|
|
codec_.height = inputImage._encodedHeight;
|
2016-03-04 14:10:50 -08:00
|
|
|
int32_t ret;
|
2016-04-12 16:39:39 -07:00
|
|
|
if (use_surface_ &&
|
|
|
|
|
(codecType_ == kVideoCodecVP8 || codecType_ == kVideoCodecH264)) {
|
|
|
|
|
// Soft codec reset - only for surface decoding.
|
2016-06-10 14:17:27 -07:00
|
|
|
ret = codec_thread_->Invoke<int32_t>(
|
|
|
|
|
RTC_FROM_HERE,
|
|
|
|
|
Bind(&MediaCodecVideoDecoder::ResetDecodeOnCodecThread, this));
|
2016-03-04 14:10:50 -08:00
|
|
|
} else {
|
|
|
|
|
// Hard codec reset.
|
|
|
|
|
ret = InitDecode(&codec_, 1);
|
|
|
|
|
}
|
2015-06-12 16:40:44 -07:00
|
|
|
if (ret < 0) {
|
2015-10-07 16:51:02 -07:00
|
|
|
ALOGE << "InitDecode failure: " << ret << " - fallback to SW codec";
|
2015-06-12 16:40:44 -07:00
|
|
|
sw_fallback_required_ = true;
|
|
|
|
|
return WEBRTC_VIDEO_CODEC_FALLBACK_SOFTWARE;
|
|
|
|
|
}
|
2015-02-18 18:42:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Always start with a complete key frame.
|
|
|
|
|
if (key_frame_required_) {
|
2017-08-28 16:24:06 -07:00
|
|
|
if (inputImage._frameType != kVideoFrameKey) {
|
2015-10-07 16:51:02 -07:00
|
|
|
ALOGE << "Decode() - key frame is required";
|
2015-02-18 18:42:55 +00:00
|
|
|
return WEBRTC_VIDEO_CODEC_ERROR;
|
|
|
|
|
}
|
|
|
|
|
if (!inputImage._completeFrame) {
|
2015-10-07 16:51:02 -07:00
|
|
|
ALOGE << "Decode() - complete frame is required";
|
2015-02-18 18:42:55 +00:00
|
|
|
return WEBRTC_VIDEO_CODEC_ERROR;
|
|
|
|
|
}
|
|
|
|
|
key_frame_required_ = false;
|
|
|
|
|
}
|
|
|
|
|
if (inputImage._length == 0) {
|
|
|
|
|
return WEBRTC_VIDEO_CODEC_ERROR;
|
|
|
|
|
}
|
|
|
|
|
|
Revert of Deliver video frames on Android, on the decode thread. (patchset #7 id:120001 of https://codereview.webrtc.org/2764573002/ )
Reason for revert:
Breaks Chrome FYI Android bots.
See:
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus9%29/builds/20418
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus6%29/builds/14724
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus5%29/builds/20133
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28K%20Nexus5%29/builds/15111
Original issue's description:
> Deliver video frames on Android, on the decode thread.
>
> VideoCoding
> * Adding a method for polling for frames on Android only until the capture implementation takes care of this (longer term plan).
>
> CodecDatabase
> * Add an accessor for the current decoder
> * Use std::unique_ptr<> for ownership.
> * Remove "Release()" and "ReleaseDecoder()". Instead just delete.
> * Remove |friend| relationship between CodecDatabase and VCMGenericDecoder.
>
> VCMDecodedFrameCallback
> * DCHECKs for thread correctness.
> * Remove |lock_| now that a threading model has been established and verified.
>
> VCMGenericDecoder
> * All methods now have thread checks.
> * Variable access associated with thread checkers.
>
> VideoReceiver
> * Added two notification methods, DecoderThreadStarting() and DecoderThreadStopped()
> * Allows us to establish a period when the decoder thread is not running and it is safe to modify variables such as callbacks, that are only read when the decoder thread is running.
> * Allows us to DCHECK thread guarantees.
> * Allows synchronizing callbacks from the module process thread and have them only active while the decoder thread is running.
> * The above, allows us to establish two modes for the thread, single-threaded-mutable and multi-threaded-const.
> * Using that knowledge, we can remove |receive_crit_| as well as locking for a number of member variables.
>
> MediaCodecVideoDecoder
> * Removed frame polling code from this class, since this is now done from the root thread function in VideoReceiveStream.
>
> VideoReceiveStream
> * On Android: Polls for decoded frames every 10ms (same interval as previously in MediaCodecVideoDecoder)
> * [Un]Registers the |video_receiver_| with the module thread only around the time the decoder thread is started/stopped.
> * Notifies the receiver of start/stop events of the decoder thread.
> * Changed the decoder thread to use the new PlatformThread callback type.
>
> BUG=webrtc:7361, 695438
>
> Review-Url: https://codereview.webrtc.org/2764573002
> Cr-Commit-Position: refs/heads/master@{#17527}
> Committed: https://chromium.googlesource.com/external/webrtc/+/e3aa88bbd5accadec73fa7e38584dfbf6aabe8a9
TBR=sakal@webrtc.org,mflodman@webrtc.org,stefan@webrtc.org,tommi@webrtc.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=webrtc:7361, 695438
Review-Url: https://codereview.webrtc.org/2792033003
Cr-Commit-Position: refs/heads/master@{#17530}
2017-04-04 07:16:21 -07:00
|
|
|
return codec_thread_->Invoke<int32_t>(
|
2016-06-10 14:17:27 -07:00
|
|
|
RTC_FROM_HERE,
|
Revert of Deliver video frames on Android, on the decode thread. (patchset #7 id:120001 of https://codereview.webrtc.org/2764573002/ )
Reason for revert:
Breaks Chrome FYI Android bots.
See:
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus9%29/builds/20418
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus6%29/builds/14724
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus5%29/builds/20133
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28K%20Nexus5%29/builds/15111
Original issue's description:
> Deliver video frames on Android, on the decode thread.
>
> VideoCoding
> * Adding a method for polling for frames on Android only until the capture implementation takes care of this (longer term plan).
>
> CodecDatabase
> * Add an accessor for the current decoder
> * Use std::unique_ptr<> for ownership.
> * Remove "Release()" and "ReleaseDecoder()". Instead just delete.
> * Remove |friend| relationship between CodecDatabase and VCMGenericDecoder.
>
> VCMDecodedFrameCallback
> * DCHECKs for thread correctness.
> * Remove |lock_| now that a threading model has been established and verified.
>
> VCMGenericDecoder
> * All methods now have thread checks.
> * Variable access associated with thread checkers.
>
> VideoReceiver
> * Added two notification methods, DecoderThreadStarting() and DecoderThreadStopped()
> * Allows us to establish a period when the decoder thread is not running and it is safe to modify variables such as callbacks, that are only read when the decoder thread is running.
> * Allows us to DCHECK thread guarantees.
> * Allows synchronizing callbacks from the module process thread and have them only active while the decoder thread is running.
> * The above, allows us to establish two modes for the thread, single-threaded-mutable and multi-threaded-const.
> * Using that knowledge, we can remove |receive_crit_| as well as locking for a number of member variables.
>
> MediaCodecVideoDecoder
> * Removed frame polling code from this class, since this is now done from the root thread function in VideoReceiveStream.
>
> VideoReceiveStream
> * On Android: Polls for decoded frames every 10ms (same interval as previously in MediaCodecVideoDecoder)
> * [Un]Registers the |video_receiver_| with the module thread only around the time the decoder thread is started/stopped.
> * Notifies the receiver of start/stop events of the decoder thread.
> * Changed the decoder thread to use the new PlatformThread callback type.
>
> BUG=webrtc:7361, 695438
>
> Review-Url: https://codereview.webrtc.org/2764573002
> Cr-Commit-Position: refs/heads/master@{#17527}
> Committed: https://chromium.googlesource.com/external/webrtc/+/e3aa88bbd5accadec73fa7e38584dfbf6aabe8a9
TBR=sakal@webrtc.org,mflodman@webrtc.org,stefan@webrtc.org,tommi@webrtc.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=webrtc:7361, 695438
Review-Url: https://codereview.webrtc.org/2792033003
Cr-Commit-Position: refs/heads/master@{#17530}
2017-04-04 07:16:21 -07:00
|
|
|
Bind(&MediaCodecVideoDecoder::DecodeOnCodecThread, this, inputImage));
|
2015-02-18 18:42:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int32_t MediaCodecVideoDecoder::DecodeOnCodecThread(
|
Revert of Deliver video frames on Android, on the decode thread. (patchset #7 id:120001 of https://codereview.webrtc.org/2764573002/ )
Reason for revert:
Breaks Chrome FYI Android bots.
See:
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus9%29/builds/20418
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus6%29/builds/14724
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus5%29/builds/20133
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28K%20Nexus5%29/builds/15111
Original issue's description:
> Deliver video frames on Android, on the decode thread.
>
> VideoCoding
> * Adding a method for polling for frames on Android only until the capture implementation takes care of this (longer term plan).
>
> CodecDatabase
> * Add an accessor for the current decoder
> * Use std::unique_ptr<> for ownership.
> * Remove "Release()" and "ReleaseDecoder()". Instead just delete.
> * Remove |friend| relationship between CodecDatabase and VCMGenericDecoder.
>
> VCMDecodedFrameCallback
> * DCHECKs for thread correctness.
> * Remove |lock_| now that a threading model has been established and verified.
>
> VCMGenericDecoder
> * All methods now have thread checks.
> * Variable access associated with thread checkers.
>
> VideoReceiver
> * Added two notification methods, DecoderThreadStarting() and DecoderThreadStopped()
> * Allows us to establish a period when the decoder thread is not running and it is safe to modify variables such as callbacks, that are only read when the decoder thread is running.
> * Allows us to DCHECK thread guarantees.
> * Allows synchronizing callbacks from the module process thread and have them only active while the decoder thread is running.
> * The above, allows us to establish two modes for the thread, single-threaded-mutable and multi-threaded-const.
> * Using that knowledge, we can remove |receive_crit_| as well as locking for a number of member variables.
>
> MediaCodecVideoDecoder
> * Removed frame polling code from this class, since this is now done from the root thread function in VideoReceiveStream.
>
> VideoReceiveStream
> * On Android: Polls for decoded frames every 10ms (same interval as previously in MediaCodecVideoDecoder)
> * [Un]Registers the |video_receiver_| with the module thread only around the time the decoder thread is started/stopped.
> * Notifies the receiver of start/stop events of the decoder thread.
> * Changed the decoder thread to use the new PlatformThread callback type.
>
> BUG=webrtc:7361, 695438
>
> Review-Url: https://codereview.webrtc.org/2764573002
> Cr-Commit-Position: refs/heads/master@{#17527}
> Committed: https://chromium.googlesource.com/external/webrtc/+/e3aa88bbd5accadec73fa7e38584dfbf6aabe8a9
TBR=sakal@webrtc.org,mflodman@webrtc.org,stefan@webrtc.org,tommi@webrtc.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=webrtc:7361, 695438
Review-Url: https://codereview.webrtc.org/2792033003
Cr-Commit-Position: refs/heads/master@{#17530}
2017-04-04 07:16:21 -07:00
|
|
|
const EncodedImage& inputImage) {
|
|
|
|
|
CheckOnCodecThread();
|
2015-02-18 18:42:55 +00:00
|
|
|
JNIEnv* jni = AttachCurrentThreadIfNeeded();
|
|
|
|
|
ScopedLocalRefFrame local_ref_frame(jni);
|
|
|
|
|
|
|
|
|
|
// Try to drain the decoder and wait until output is not too
|
|
|
|
|
// much behind the input.
|
2016-03-04 14:10:50 -08:00
|
|
|
if (codecType_ == kVideoCodecH264 &&
|
|
|
|
|
frames_received_ > frames_decoded_ + max_pending_frames_) {
|
|
|
|
|
// Print warning for H.264 only - for VP8/VP9 one frame delay is ok.
|
2016-02-04 11:47:12 -08:00
|
|
|
ALOGW << "Decoder is too far behind. Try to drain. Received: "
|
|
|
|
|
<< frames_received_ << ". Decoded: " << frames_decoded_;
|
|
|
|
|
EnableFrameLogOnWarning();
|
|
|
|
|
}
|
2018-07-09 21:41:33 +02:00
|
|
|
const int64_t drain_start = rtc::TimeMillis();
|
2015-11-19 10:43:36 +01:00
|
|
|
while ((frames_received_ > frames_decoded_ + max_pending_frames_) &&
|
2016-05-10 16:31:47 +02:00
|
|
|
(rtc::TimeMillis() - drain_start) < kMediaCodecTimeoutMs) {
|
Revert of Deliver video frames on Android, on the decode thread. (patchset #7 id:120001 of https://codereview.webrtc.org/2764573002/ )
Reason for revert:
Breaks Chrome FYI Android bots.
See:
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus9%29/builds/20418
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus6%29/builds/14724
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus5%29/builds/20133
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28K%20Nexus5%29/builds/15111
Original issue's description:
> Deliver video frames on Android, on the decode thread.
>
> VideoCoding
> * Adding a method for polling for frames on Android only until the capture implementation takes care of this (longer term plan).
>
> CodecDatabase
> * Add an accessor for the current decoder
> * Use std::unique_ptr<> for ownership.
> * Remove "Release()" and "ReleaseDecoder()". Instead just delete.
> * Remove |friend| relationship between CodecDatabase and VCMGenericDecoder.
>
> VCMDecodedFrameCallback
> * DCHECKs for thread correctness.
> * Remove |lock_| now that a threading model has been established and verified.
>
> VCMGenericDecoder
> * All methods now have thread checks.
> * Variable access associated with thread checkers.
>
> VideoReceiver
> * Added two notification methods, DecoderThreadStarting() and DecoderThreadStopped()
> * Allows us to establish a period when the decoder thread is not running and it is safe to modify variables such as callbacks, that are only read when the decoder thread is running.
> * Allows us to DCHECK thread guarantees.
> * Allows synchronizing callbacks from the module process thread and have them only active while the decoder thread is running.
> * The above, allows us to establish two modes for the thread, single-threaded-mutable and multi-threaded-const.
> * Using that knowledge, we can remove |receive_crit_| as well as locking for a number of member variables.
>
> MediaCodecVideoDecoder
> * Removed frame polling code from this class, since this is now done from the root thread function in VideoReceiveStream.
>
> VideoReceiveStream
> * On Android: Polls for decoded frames every 10ms (same interval as previously in MediaCodecVideoDecoder)
> * [Un]Registers the |video_receiver_| with the module thread only around the time the decoder thread is started/stopped.
> * Notifies the receiver of start/stop events of the decoder thread.
> * Changed the decoder thread to use the new PlatformThread callback type.
>
> BUG=webrtc:7361, 695438
>
> Review-Url: https://codereview.webrtc.org/2764573002
> Cr-Commit-Position: refs/heads/master@{#17527}
> Committed: https://chromium.googlesource.com/external/webrtc/+/e3aa88bbd5accadec73fa7e38584dfbf6aabe8a9
TBR=sakal@webrtc.org,mflodman@webrtc.org,stefan@webrtc.org,tommi@webrtc.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=webrtc:7361, 695438
Review-Url: https://codereview.webrtc.org/2792033003
Cr-Commit-Position: refs/heads/master@{#17530}
2017-04-04 07:16:21 -07:00
|
|
|
if (!DeliverPendingOutputs(jni, kMediaCodecPollMs)) {
|
2015-10-28 10:30:32 -07:00
|
|
|
ALOGE << "DeliverPendingOutputs error. Frames received: "
|
|
|
|
|
<< frames_received_ << ". Frames decoded: " << frames_decoded_;
|
2015-06-12 16:40:44 -07:00
|
|
|
return ProcessHWErrorOnCodecThread();
|
2015-02-18 18:42:55 +00:00
|
|
|
}
|
2015-11-19 10:43:36 +01:00
|
|
|
}
|
|
|
|
|
if (frames_received_ > frames_decoded_ + max_pending_frames_) {
|
|
|
|
|
ALOGE << "Output buffer dequeue timeout. Frames received: "
|
|
|
|
|
<< frames_received_ << ". Frames decoded: " << frames_decoded_;
|
|
|
|
|
return ProcessHWErrorOnCodecThread();
|
2015-02-18 18:42:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get input buffer.
|
2017-12-08 11:05:22 +01:00
|
|
|
int j_input_buffer_index = Java_MediaCodecVideoDecoder_dequeueInputBuffer(
|
2017-12-20 15:12:10 +01:00
|
|
|
jni, j_media_codec_video_decoder_);
|
2015-06-12 16:40:44 -07:00
|
|
|
if (CheckException(jni) || j_input_buffer_index < 0) {
|
2016-02-04 11:47:12 -08:00
|
|
|
ALOGE << "dequeueInputBuffer error: " << j_input_buffer_index
|
|
|
|
|
<< ". Retry DeliverPendingOutputs.";
|
|
|
|
|
EnableFrameLogOnWarning();
|
|
|
|
|
// Try to drain the decoder.
|
Revert of Deliver video frames on Android, on the decode thread. (patchset #7 id:120001 of https://codereview.webrtc.org/2764573002/ )
Reason for revert:
Breaks Chrome FYI Android bots.
See:
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus9%29/builds/20418
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus6%29/builds/14724
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus5%29/builds/20133
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28K%20Nexus5%29/builds/15111
Original issue's description:
> Deliver video frames on Android, on the decode thread.
>
> VideoCoding
> * Adding a method for polling for frames on Android only until the capture implementation takes care of this (longer term plan).
>
> CodecDatabase
> * Add an accessor for the current decoder
> * Use std::unique_ptr<> for ownership.
> * Remove "Release()" and "ReleaseDecoder()". Instead just delete.
> * Remove |friend| relationship between CodecDatabase and VCMGenericDecoder.
>
> VCMDecodedFrameCallback
> * DCHECKs for thread correctness.
> * Remove |lock_| now that a threading model has been established and verified.
>
> VCMGenericDecoder
> * All methods now have thread checks.
> * Variable access associated with thread checkers.
>
> VideoReceiver
> * Added two notification methods, DecoderThreadStarting() and DecoderThreadStopped()
> * Allows us to establish a period when the decoder thread is not running and it is safe to modify variables such as callbacks, that are only read when the decoder thread is running.
> * Allows us to DCHECK thread guarantees.
> * Allows synchronizing callbacks from the module process thread and have them only active while the decoder thread is running.
> * The above, allows us to establish two modes for the thread, single-threaded-mutable and multi-threaded-const.
> * Using that knowledge, we can remove |receive_crit_| as well as locking for a number of member variables.
>
> MediaCodecVideoDecoder
> * Removed frame polling code from this class, since this is now done from the root thread function in VideoReceiveStream.
>
> VideoReceiveStream
> * On Android: Polls for decoded frames every 10ms (same interval as previously in MediaCodecVideoDecoder)
> * [Un]Registers the |video_receiver_| with the module thread only around the time the decoder thread is started/stopped.
> * Notifies the receiver of start/stop events of the decoder thread.
> * Changed the decoder thread to use the new PlatformThread callback type.
>
> BUG=webrtc:7361, 695438
>
> Review-Url: https://codereview.webrtc.org/2764573002
> Cr-Commit-Position: refs/heads/master@{#17527}
> Committed: https://chromium.googlesource.com/external/webrtc/+/e3aa88bbd5accadec73fa7e38584dfbf6aabe8a9
TBR=sakal@webrtc.org,mflodman@webrtc.org,stefan@webrtc.org,tommi@webrtc.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=webrtc:7361, 695438
Review-Url: https://codereview.webrtc.org/2792033003
Cr-Commit-Position: refs/heads/master@{#17530}
2017-04-04 07:16:21 -07:00
|
|
|
if (!DeliverPendingOutputs(jni, kMediaCodecPollMs)) {
|
2016-02-04 11:47:12 -08:00
|
|
|
ALOGE << "DeliverPendingOutputs error. Frames received: "
|
|
|
|
|
<< frames_received_ << ". Frames decoded: " << frames_decoded_;
|
|
|
|
|
return ProcessHWErrorOnCodecThread();
|
|
|
|
|
}
|
|
|
|
|
// Try dequeue input buffer one last time.
|
2017-12-08 11:05:22 +01:00
|
|
|
j_input_buffer_index = Java_MediaCodecVideoDecoder_dequeueInputBuffer(
|
2017-12-20 15:12:10 +01:00
|
|
|
jni, j_media_codec_video_decoder_);
|
2016-02-04 11:47:12 -08:00
|
|
|
if (CheckException(jni) || j_input_buffer_index < 0) {
|
|
|
|
|
ALOGE << "dequeueInputBuffer critical error: " << j_input_buffer_index;
|
|
|
|
|
return ProcessHWErrorOnCodecThread();
|
|
|
|
|
}
|
2015-02-18 18:42:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Copy encoded data to Java ByteBuffer.
|
2017-12-20 15:12:10 +01:00
|
|
|
jobject j_input_buffer = input_buffers_[j_input_buffer_index].obj();
|
Use suffixed {uint,int}{8,16,32,64}_t types.
Removes the use of uint8, etc. in favor of uint8_t.
BUG=webrtc:5024
R=henrik.lundin@webrtc.org, henrikg@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1362503003 .
Cr-Commit-Position: refs/heads/master@{#10196}
2015-10-07 12:23:21 +02:00
|
|
|
uint8_t* buffer =
|
|
|
|
|
reinterpret_cast<uint8_t*>(jni->GetDirectBufferAddress(j_input_buffer));
|
Revert of Deliver video frames on Android, on the decode thread. (patchset #7 id:120001 of https://codereview.webrtc.org/2764573002/ )
Reason for revert:
Breaks Chrome FYI Android bots.
See:
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus9%29/builds/20418
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus6%29/builds/14724
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus5%29/builds/20133
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28K%20Nexus5%29/builds/15111
Original issue's description:
> Deliver video frames on Android, on the decode thread.
>
> VideoCoding
> * Adding a method for polling for frames on Android only until the capture implementation takes care of this (longer term plan).
>
> CodecDatabase
> * Add an accessor for the current decoder
> * Use std::unique_ptr<> for ownership.
> * Remove "Release()" and "ReleaseDecoder()". Instead just delete.
> * Remove |friend| relationship between CodecDatabase and VCMGenericDecoder.
>
> VCMDecodedFrameCallback
> * DCHECKs for thread correctness.
> * Remove |lock_| now that a threading model has been established and verified.
>
> VCMGenericDecoder
> * All methods now have thread checks.
> * Variable access associated with thread checkers.
>
> VideoReceiver
> * Added two notification methods, DecoderThreadStarting() and DecoderThreadStopped()
> * Allows us to establish a period when the decoder thread is not running and it is safe to modify variables such as callbacks, that are only read when the decoder thread is running.
> * Allows us to DCHECK thread guarantees.
> * Allows synchronizing callbacks from the module process thread and have them only active while the decoder thread is running.
> * The above, allows us to establish two modes for the thread, single-threaded-mutable and multi-threaded-const.
> * Using that knowledge, we can remove |receive_crit_| as well as locking for a number of member variables.
>
> MediaCodecVideoDecoder
> * Removed frame polling code from this class, since this is now done from the root thread function in VideoReceiveStream.
>
> VideoReceiveStream
> * On Android: Polls for decoded frames every 10ms (same interval as previously in MediaCodecVideoDecoder)
> * [Un]Registers the |video_receiver_| with the module thread only around the time the decoder thread is started/stopped.
> * Notifies the receiver of start/stop events of the decoder thread.
> * Changed the decoder thread to use the new PlatformThread callback type.
>
> BUG=webrtc:7361, 695438
>
> Review-Url: https://codereview.webrtc.org/2764573002
> Cr-Commit-Position: refs/heads/master@{#17527}
> Committed: https://chromium.googlesource.com/external/webrtc/+/e3aa88bbd5accadec73fa7e38584dfbf6aabe8a9
TBR=sakal@webrtc.org,mflodman@webrtc.org,stefan@webrtc.org,tommi@webrtc.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=webrtc:7361, 695438
Review-Url: https://codereview.webrtc.org/2792033003
Cr-Commit-Position: refs/heads/master@{#17530}
2017-04-04 07:16:21 -07:00
|
|
|
RTC_CHECK(buffer) << "Indirect buffer??";
|
2018-06-01 14:54:29 +02:00
|
|
|
size_t buffer_capacity =
|
|
|
|
|
rtc::dchecked_cast<size_t>(jni->GetDirectBufferCapacity(j_input_buffer));
|
2015-06-12 16:40:44 -07:00
|
|
|
if (CheckException(jni) || buffer_capacity < inputImage._length) {
|
2015-10-07 16:51:02 -07:00
|
|
|
ALOGE << "Input frame size " << inputImage._length
|
|
|
|
|
<< " is bigger than buffer size " << buffer_capacity;
|
2015-06-12 16:40:44 -07:00
|
|
|
return ProcessHWErrorOnCodecThread();
|
2015-02-18 18:42:55 +00:00
|
|
|
}
|
2016-02-04 11:47:12 -08:00
|
|
|
jlong presentation_timestamp_us = static_cast<jlong>(
|
|
|
|
|
static_cast<int64_t>(frames_received_) * 1000000 / codec_.maxFramerate);
|
2016-02-01 13:17:18 -08:00
|
|
|
memcpy(buffer, inputImage._buffer, inputImage._length);
|
|
|
|
|
|
2016-02-04 11:47:12 -08:00
|
|
|
if (frames_decoded_ < frames_decoded_logged_) {
|
2016-02-01 13:17:18 -08:00
|
|
|
ALOGD << "Decoder frame in # " << frames_received_
|
|
|
|
|
<< ". Type: " << inputImage._frameType << ". Buffer # "
|
|
|
|
|
<< j_input_buffer_index
|
2016-02-04 11:47:12 -08:00
|
|
|
<< ". TS: " << presentation_timestamp_us / 1000
|
2016-02-01 13:17:18 -08:00
|
|
|
<< ". Size: " << inputImage._length;
|
2015-10-28 10:30:32 -07:00
|
|
|
}
|
2015-02-18 18:42:55 +00:00
|
|
|
|
|
|
|
|
// Save input image timestamps for later output.
|
|
|
|
|
frames_received_++;
|
|
|
|
|
current_bytes_ += inputImage._length;
|
2018-06-21 10:17:24 +02:00
|
|
|
absl::optional<uint8_t> qp;
|
2017-02-17 03:26:10 -08:00
|
|
|
if (codecType_ == kVideoCodecVP8) {
|
|
|
|
|
int qp_int;
|
2017-08-28 16:24:06 -07:00
|
|
|
if (vp8::GetQp(inputImage._buffer, inputImage._length, &qp_int)) {
|
2017-11-16 10:52:24 +01:00
|
|
|
qp = qp_int;
|
2017-02-17 03:26:10 -08:00
|
|
|
}
|
|
|
|
|
} else if (codecType_ == kVideoCodecH264) {
|
|
|
|
|
h264_bitstream_parser_.ParseBitstream(inputImage._buffer,
|
|
|
|
|
inputImage._length);
|
|
|
|
|
int qp_int;
|
|
|
|
|
if (h264_bitstream_parser_.GetLastSliceQp(&qp_int)) {
|
2017-11-16 10:52:24 +01:00
|
|
|
qp = qp_int;
|
2017-02-17 03:26:10 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
pending_frame_qps_.push_back(qp);
|
2015-02-18 18:42:55 +00:00
|
|
|
|
|
|
|
|
// Feed input to decoder.
|
2017-12-08 11:05:22 +01:00
|
|
|
bool success = Java_MediaCodecVideoDecoder_queueInputBuffer(
|
2017-12-20 15:12:10 +01:00
|
|
|
jni, j_media_codec_video_decoder_, j_input_buffer_index,
|
2018-05-08 10:51:00 +02:00
|
|
|
static_cast<int>(inputImage._length), presentation_timestamp_us,
|
2017-12-08 11:05:22 +01:00
|
|
|
static_cast<int64_t>(inputImage._timeStamp), inputImage.ntp_time_ms_);
|
2015-06-12 16:40:44 -07:00
|
|
|
if (CheckException(jni) || !success) {
|
2015-10-07 16:51:02 -07:00
|
|
|
ALOGE << "queueInputBuffer error";
|
2015-06-12 16:40:44 -07:00
|
|
|
return ProcessHWErrorOnCodecThread();
|
2015-02-18 18:42:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Try to drain the decoder
|
Revert of Deliver video frames on Android, on the decode thread. (patchset #7 id:120001 of https://codereview.webrtc.org/2764573002/ )
Reason for revert:
Breaks Chrome FYI Android bots.
See:
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus9%29/builds/20418
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus6%29/builds/14724
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus5%29/builds/20133
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28K%20Nexus5%29/builds/15111
Original issue's description:
> Deliver video frames on Android, on the decode thread.
>
> VideoCoding
> * Adding a method for polling for frames on Android only until the capture implementation takes care of this (longer term plan).
>
> CodecDatabase
> * Add an accessor for the current decoder
> * Use std::unique_ptr<> for ownership.
> * Remove "Release()" and "ReleaseDecoder()". Instead just delete.
> * Remove |friend| relationship between CodecDatabase and VCMGenericDecoder.
>
> VCMDecodedFrameCallback
> * DCHECKs for thread correctness.
> * Remove |lock_| now that a threading model has been established and verified.
>
> VCMGenericDecoder
> * All methods now have thread checks.
> * Variable access associated with thread checkers.
>
> VideoReceiver
> * Added two notification methods, DecoderThreadStarting() and DecoderThreadStopped()
> * Allows us to establish a period when the decoder thread is not running and it is safe to modify variables such as callbacks, that are only read when the decoder thread is running.
> * Allows us to DCHECK thread guarantees.
> * Allows synchronizing callbacks from the module process thread and have them only active while the decoder thread is running.
> * The above, allows us to establish two modes for the thread, single-threaded-mutable and multi-threaded-const.
> * Using that knowledge, we can remove |receive_crit_| as well as locking for a number of member variables.
>
> MediaCodecVideoDecoder
> * Removed frame polling code from this class, since this is now done from the root thread function in VideoReceiveStream.
>
> VideoReceiveStream
> * On Android: Polls for decoded frames every 10ms (same interval as previously in MediaCodecVideoDecoder)
> * [Un]Registers the |video_receiver_| with the module thread only around the time the decoder thread is started/stopped.
> * Notifies the receiver of start/stop events of the decoder thread.
> * Changed the decoder thread to use the new PlatformThread callback type.
>
> BUG=webrtc:7361, 695438
>
> Review-Url: https://codereview.webrtc.org/2764573002
> Cr-Commit-Position: refs/heads/master@{#17527}
> Committed: https://chromium.googlesource.com/external/webrtc/+/e3aa88bbd5accadec73fa7e38584dfbf6aabe8a9
TBR=sakal@webrtc.org,mflodman@webrtc.org,stefan@webrtc.org,tommi@webrtc.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=webrtc:7361, 695438
Review-Url: https://codereview.webrtc.org/2792033003
Cr-Commit-Position: refs/heads/master@{#17530}
2017-04-04 07:16:21 -07:00
|
|
|
if (!DeliverPendingOutputs(jni, 0)) {
|
2015-10-07 16:51:02 -07:00
|
|
|
ALOGE << "DeliverPendingOutputs error";
|
2015-06-12 16:40:44 -07:00
|
|
|
return ProcessHWErrorOnCodecThread();
|
2015-02-18 18:42:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return WEBRTC_VIDEO_CODEC_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool MediaCodecVideoDecoder::DeliverPendingOutputs(JNIEnv* jni,
|
Revert of Deliver video frames on Android, on the decode thread. (patchset #7 id:120001 of https://codereview.webrtc.org/2764573002/ )
Reason for revert:
Breaks Chrome FYI Android bots.
See:
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus9%29/builds/20418
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus6%29/builds/14724
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus5%29/builds/20133
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28K%20Nexus5%29/builds/15111
Original issue's description:
> Deliver video frames on Android, on the decode thread.
>
> VideoCoding
> * Adding a method for polling for frames on Android only until the capture implementation takes care of this (longer term plan).
>
> CodecDatabase
> * Add an accessor for the current decoder
> * Use std::unique_ptr<> for ownership.
> * Remove "Release()" and "ReleaseDecoder()". Instead just delete.
> * Remove |friend| relationship between CodecDatabase and VCMGenericDecoder.
>
> VCMDecodedFrameCallback
> * DCHECKs for thread correctness.
> * Remove |lock_| now that a threading model has been established and verified.
>
> VCMGenericDecoder
> * All methods now have thread checks.
> * Variable access associated with thread checkers.
>
> VideoReceiver
> * Added two notification methods, DecoderThreadStarting() and DecoderThreadStopped()
> * Allows us to establish a period when the decoder thread is not running and it is safe to modify variables such as callbacks, that are only read when the decoder thread is running.
> * Allows us to DCHECK thread guarantees.
> * Allows synchronizing callbacks from the module process thread and have them only active while the decoder thread is running.
> * The above, allows us to establish two modes for the thread, single-threaded-mutable and multi-threaded-const.
> * Using that knowledge, we can remove |receive_crit_| as well as locking for a number of member variables.
>
> MediaCodecVideoDecoder
> * Removed frame polling code from this class, since this is now done from the root thread function in VideoReceiveStream.
>
> VideoReceiveStream
> * On Android: Polls for decoded frames every 10ms (same interval as previously in MediaCodecVideoDecoder)
> * [Un]Registers the |video_receiver_| with the module thread only around the time the decoder thread is started/stopped.
> * Notifies the receiver of start/stop events of the decoder thread.
> * Changed the decoder thread to use the new PlatformThread callback type.
>
> BUG=webrtc:7361, 695438
>
> Review-Url: https://codereview.webrtc.org/2764573002
> Cr-Commit-Position: refs/heads/master@{#17527}
> Committed: https://chromium.googlesource.com/external/webrtc/+/e3aa88bbd5accadec73fa7e38584dfbf6aabe8a9
TBR=sakal@webrtc.org,mflodman@webrtc.org,stefan@webrtc.org,tommi@webrtc.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=webrtc:7361, 695438
Review-Url: https://codereview.webrtc.org/2792033003
Cr-Commit-Position: refs/heads/master@{#17530}
2017-04-04 07:16:21 -07:00
|
|
|
int dequeue_timeout_ms) {
|
|
|
|
|
CheckOnCodecThread();
|
2015-02-18 18:42:55 +00:00
|
|
|
if (frames_received_ <= frames_decoded_) {
|
|
|
|
|
// No need to query for output buffers - decoder is drained.
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
// Get decoder output.
|
2017-12-20 15:12:10 +01:00
|
|
|
ScopedJavaLocalRef<jobject> j_decoder_output_buffer =
|
2017-12-08 11:05:22 +01:00
|
|
|
(use_surface_ ? &Java_MediaCodecVideoDecoder_dequeueTextureBuffer
|
|
|
|
|
: &Java_MediaCodecVideoDecoder_dequeueOutputBuffer)(
|
2017-12-20 15:12:10 +01:00
|
|
|
jni, j_media_codec_video_decoder_, dequeue_timeout_ms);
|
2015-06-12 16:40:44 -07:00
|
|
|
if (CheckException(jni)) {
|
2015-10-07 16:51:02 -07:00
|
|
|
ALOGE << "dequeueOutputBuffer() error";
|
2015-06-12 16:40:44 -07:00
|
|
|
return false;
|
|
|
|
|
}
|
2015-10-03 02:08:00 -07:00
|
|
|
if (IsNull(jni, j_decoder_output_buffer)) {
|
|
|
|
|
// No decoded frame ready.
|
2015-02-18 18:42:55 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get decoded video frame properties.
|
2017-12-08 11:05:22 +01:00
|
|
|
int color_format = Java_MediaCodecVideoDecoder_getColorFormat(
|
2017-12-20 15:12:10 +01:00
|
|
|
jni, j_media_codec_video_decoder_);
|
2017-12-08 11:05:22 +01:00
|
|
|
int width =
|
2017-12-20 15:12:10 +01:00
|
|
|
Java_MediaCodecVideoDecoder_getWidth(jni, j_media_codec_video_decoder_);
|
2017-12-08 11:05:22 +01:00
|
|
|
int height =
|
2017-12-20 15:12:10 +01:00
|
|
|
Java_MediaCodecVideoDecoder_getHeight(jni, j_media_codec_video_decoder_);
|
2015-02-18 18:42:55 +00:00
|
|
|
|
2017-08-28 16:24:06 -07:00
|
|
|
rtc::scoped_refptr<VideoFrameBuffer> frame_buffer;
|
2016-02-01 13:17:18 -08:00
|
|
|
int64_t presentation_timestamps_ms = 0;
|
2015-11-19 10:43:36 +01:00
|
|
|
int64_t output_timestamps_ms = 0;
|
|
|
|
|
int64_t output_ntp_timestamps_ms = 0;
|
|
|
|
|
int decode_time_ms = 0;
|
|
|
|
|
int64_t frame_delayed_ms = 0;
|
2015-09-30 16:06:37 +02:00
|
|
|
if (use_surface_) {
|
2015-10-03 02:08:00 -07:00
|
|
|
// Extract data from Java DecodedTextureBuffer.
|
2017-12-08 11:05:22 +01:00
|
|
|
presentation_timestamps_ms =
|
|
|
|
|
Java_DecodedTextureBuffer_getPresentationTimestampMs(
|
|
|
|
|
jni, j_decoder_output_buffer);
|
|
|
|
|
output_timestamps_ms =
|
|
|
|
|
Java_DecodedTextureBuffer_getTimeStampMs(jni, j_decoder_output_buffer);
|
|
|
|
|
output_ntp_timestamps_ms = Java_DecodedTextureBuffer_getNtpTimestampMs(
|
|
|
|
|
jni, j_decoder_output_buffer);
|
|
|
|
|
decode_time_ms =
|
|
|
|
|
Java_DecodedTextureBuffer_getDecodeTimeMs(jni, j_decoder_output_buffer);
|
2016-02-04 11:47:12 -08:00
|
|
|
|
2018-04-23 11:29:05 +02:00
|
|
|
ScopedJavaLocalRef<jobject> j_video_frame_buffer =
|
|
|
|
|
Java_DecodedTextureBuffer_getVideoFrameBuffer(jni,
|
|
|
|
|
j_decoder_output_buffer);
|
|
|
|
|
// |video_frame_buffer| == null represents a dropped frame.
|
|
|
|
|
if (!j_video_frame_buffer.is_null()) {
|
2017-12-08 11:05:22 +01:00
|
|
|
frame_delayed_ms = Java_DecodedTextureBuffer_getFrameDelayMs(
|
|
|
|
|
jni, j_decoder_output_buffer);
|
2018-04-23 11:29:05 +02:00
|
|
|
frame_buffer = AndroidVideoBuffer::Adopt(jni, j_video_frame_buffer);
|
2016-02-04 11:47:12 -08:00
|
|
|
} else {
|
|
|
|
|
EnableFrameLogOnWarning();
|
2015-11-19 10:43:36 +01:00
|
|
|
}
|
2015-09-30 16:06:37 +02:00
|
|
|
} else {
|
|
|
|
|
// Extract data from Java ByteBuffer and create output yuv420 frame -
|
|
|
|
|
// for non surface decoding only.
|
2017-12-08 11:05:22 +01:00
|
|
|
int stride = Java_MediaCodecVideoDecoder_getStride(
|
2017-12-20 15:12:10 +01:00
|
|
|
jni, j_media_codec_video_decoder_);
|
2017-12-08 11:05:22 +01:00
|
|
|
const int slice_height = Java_MediaCodecVideoDecoder_getSliceHeight(
|
2017-12-20 15:12:10 +01:00
|
|
|
jni, j_media_codec_video_decoder_);
|
2017-12-08 11:05:22 +01:00
|
|
|
const int output_buffer_index =
|
|
|
|
|
Java_DecodedOutputBuffer_getIndex(jni, j_decoder_output_buffer);
|
|
|
|
|
const int output_buffer_offset =
|
|
|
|
|
Java_DecodedOutputBuffer_getOffset(jni, j_decoder_output_buffer);
|
|
|
|
|
const int output_buffer_size =
|
|
|
|
|
Java_DecodedOutputBuffer_getSize(jni, j_decoder_output_buffer);
|
|
|
|
|
presentation_timestamps_ms =
|
|
|
|
|
Java_DecodedOutputBuffer_getPresentationTimestampMs(
|
|
|
|
|
jni, j_decoder_output_buffer);
|
|
|
|
|
output_timestamps_ms =
|
|
|
|
|
Java_DecodedOutputBuffer_getTimestampMs(jni, j_decoder_output_buffer);
|
|
|
|
|
output_ntp_timestamps_ms = Java_DecodedOutputBuffer_getNtpTimestampMs(
|
|
|
|
|
jni, j_decoder_output_buffer);
|
|
|
|
|
|
|
|
|
|
decode_time_ms =
|
|
|
|
|
Java_DecodedOutputBuffer_getDecodeTimeMs(jni, j_decoder_output_buffer);
|
2017-03-06 05:20:49 -08:00
|
|
|
RTC_CHECK_GE(slice_height, height);
|
2015-10-03 02:08:00 -07:00
|
|
|
|
2015-02-18 18:42:55 +00:00
|
|
|
if (output_buffer_size < width * height * 3 / 2) {
|
2015-10-07 16:51:02 -07:00
|
|
|
ALOGE << "Insufficient output buffer size: " << output_buffer_size;
|
2015-02-18 18:42:55 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
2016-03-08 10:35:33 -08:00
|
|
|
if (output_buffer_size < stride * height * 3 / 2 &&
|
|
|
|
|
slice_height == height && stride > width) {
|
|
|
|
|
// Some codecs (Exynos) incorrectly report stride information for
|
|
|
|
|
// output byte buffer, so actual stride value need to be corrected.
|
|
|
|
|
stride = output_buffer_size * 2 / (height * 3);
|
|
|
|
|
}
|
2017-12-20 15:12:10 +01:00
|
|
|
ScopedJavaLocalRef<jobjectArray> output_buffers =
|
|
|
|
|
Java_MediaCodecVideoDecoder_getOutputBuffers(
|
|
|
|
|
jni, j_media_codec_video_decoder_);
|
2015-02-18 18:42:55 +00:00
|
|
|
jobject output_buffer =
|
2017-12-20 15:12:10 +01:00
|
|
|
jni->GetObjectArrayElement(output_buffers.obj(), output_buffer_index);
|
2015-02-18 18:42:55 +00:00
|
|
|
uint8_t* payload =
|
|
|
|
|
reinterpret_cast<uint8_t*>(jni->GetDirectBufferAddress(output_buffer));
|
2015-06-12 16:40:44 -07:00
|
|
|
if (CheckException(jni)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2015-02-18 18:42:55 +00:00
|
|
|
payload += output_buffer_offset;
|
|
|
|
|
|
|
|
|
|
// Create yuv420 frame.
|
2017-08-28 16:24:06 -07:00
|
|
|
rtc::scoped_refptr<I420Buffer> i420_buffer =
|
2017-02-23 07:11:32 -08:00
|
|
|
decoded_frame_pool_.CreateBuffer(width, height);
|
2015-02-18 18:42:55 +00:00
|
|
|
if (color_format == COLOR_FormatYUV420Planar) {
|
Revert of Deliver video frames on Android, on the decode thread. (patchset #7 id:120001 of https://codereview.webrtc.org/2764573002/ )
Reason for revert:
Breaks Chrome FYI Android bots.
See:
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus9%29/builds/20418
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus6%29/builds/14724
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus5%29/builds/20133
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28K%20Nexus5%29/builds/15111
Original issue's description:
> Deliver video frames on Android, on the decode thread.
>
> VideoCoding
> * Adding a method for polling for frames on Android only until the capture implementation takes care of this (longer term plan).
>
> CodecDatabase
> * Add an accessor for the current decoder
> * Use std::unique_ptr<> for ownership.
> * Remove "Release()" and "ReleaseDecoder()". Instead just delete.
> * Remove |friend| relationship between CodecDatabase and VCMGenericDecoder.
>
> VCMDecodedFrameCallback
> * DCHECKs for thread correctness.
> * Remove |lock_| now that a threading model has been established and verified.
>
> VCMGenericDecoder
> * All methods now have thread checks.
> * Variable access associated with thread checkers.
>
> VideoReceiver
> * Added two notification methods, DecoderThreadStarting() and DecoderThreadStopped()
> * Allows us to establish a period when the decoder thread is not running and it is safe to modify variables such as callbacks, that are only read when the decoder thread is running.
> * Allows us to DCHECK thread guarantees.
> * Allows synchronizing callbacks from the module process thread and have them only active while the decoder thread is running.
> * The above, allows us to establish two modes for the thread, single-threaded-mutable and multi-threaded-const.
> * Using that knowledge, we can remove |receive_crit_| as well as locking for a number of member variables.
>
> MediaCodecVideoDecoder
> * Removed frame polling code from this class, since this is now done from the root thread function in VideoReceiveStream.
>
> VideoReceiveStream
> * On Android: Polls for decoded frames every 10ms (same interval as previously in MediaCodecVideoDecoder)
> * [Un]Registers the |video_receiver_| with the module thread only around the time the decoder thread is started/stopped.
> * Notifies the receiver of start/stop events of the decoder thread.
> * Changed the decoder thread to use the new PlatformThread callback type.
>
> BUG=webrtc:7361, 695438
>
> Review-Url: https://codereview.webrtc.org/2764573002
> Cr-Commit-Position: refs/heads/master@{#17527}
> Committed: https://chromium.googlesource.com/external/webrtc/+/e3aa88bbd5accadec73fa7e38584dfbf6aabe8a9
TBR=sakal@webrtc.org,mflodman@webrtc.org,stefan@webrtc.org,tommi@webrtc.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=webrtc:7361, 695438
Review-Url: https://codereview.webrtc.org/2792033003
Cr-Commit-Position: refs/heads/master@{#17530}
2017-04-04 07:16:21 -07:00
|
|
|
RTC_CHECK_EQ(0, stride % 2);
|
2015-09-30 16:06:37 +02:00
|
|
|
const int uv_stride = stride / 2;
|
|
|
|
|
const uint8_t* y_ptr = payload;
|
|
|
|
|
const uint8_t* u_ptr = y_ptr + stride * slice_height;
|
2017-02-23 07:11:32 -08:00
|
|
|
|
|
|
|
|
// Note that the case with odd |slice_height| is handled in a special way.
|
|
|
|
|
// The chroma height contained in the payload is rounded down instead of
|
|
|
|
|
// up, making it one row less than what we expect in WebRTC. Therefore, we
|
|
|
|
|
// have to duplicate the last chroma rows for this case. Also, the offset
|
|
|
|
|
// between the Y plane and the U plane is unintuitive for this case. See
|
|
|
|
|
// http://bugs.webrtc.org/6651 for more info.
|
|
|
|
|
const int chroma_width = (width + 1) / 2;
|
|
|
|
|
const int chroma_height =
|
|
|
|
|
(slice_height % 2 == 0) ? (height + 1) / 2 : height / 2;
|
|
|
|
|
const int u_offset = uv_stride * slice_height / 2;
|
|
|
|
|
const uint8_t* v_ptr = u_ptr + u_offset;
|
|
|
|
|
libyuv::CopyPlane(y_ptr, stride, i420_buffer->MutableDataY(),
|
|
|
|
|
i420_buffer->StrideY(), width, height);
|
|
|
|
|
libyuv::CopyPlane(u_ptr, uv_stride, i420_buffer->MutableDataU(),
|
|
|
|
|
i420_buffer->StrideU(), chroma_width, chroma_height);
|
|
|
|
|
libyuv::CopyPlane(v_ptr, uv_stride, i420_buffer->MutableDataV(),
|
|
|
|
|
i420_buffer->StrideV(), chroma_width, chroma_height);
|
|
|
|
|
if (slice_height % 2 == 1) {
|
Revert of Deliver video frames on Android, on the decode thread. (patchset #7 id:120001 of https://codereview.webrtc.org/2764573002/ )
Reason for revert:
Breaks Chrome FYI Android bots.
See:
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus9%29/builds/20418
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus6%29/builds/14724
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus5%29/builds/20133
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28K%20Nexus5%29/builds/15111
Original issue's description:
> Deliver video frames on Android, on the decode thread.
>
> VideoCoding
> * Adding a method for polling for frames on Android only until the capture implementation takes care of this (longer term plan).
>
> CodecDatabase
> * Add an accessor for the current decoder
> * Use std::unique_ptr<> for ownership.
> * Remove "Release()" and "ReleaseDecoder()". Instead just delete.
> * Remove |friend| relationship between CodecDatabase and VCMGenericDecoder.
>
> VCMDecodedFrameCallback
> * DCHECKs for thread correctness.
> * Remove |lock_| now that a threading model has been established and verified.
>
> VCMGenericDecoder
> * All methods now have thread checks.
> * Variable access associated with thread checkers.
>
> VideoReceiver
> * Added two notification methods, DecoderThreadStarting() and DecoderThreadStopped()
> * Allows us to establish a period when the decoder thread is not running and it is safe to modify variables such as callbacks, that are only read when the decoder thread is running.
> * Allows us to DCHECK thread guarantees.
> * Allows synchronizing callbacks from the module process thread and have them only active while the decoder thread is running.
> * The above, allows us to establish two modes for the thread, single-threaded-mutable and multi-threaded-const.
> * Using that knowledge, we can remove |receive_crit_| as well as locking for a number of member variables.
>
> MediaCodecVideoDecoder
> * Removed frame polling code from this class, since this is now done from the root thread function in VideoReceiveStream.
>
> VideoReceiveStream
> * On Android: Polls for decoded frames every 10ms (same interval as previously in MediaCodecVideoDecoder)
> * [Un]Registers the |video_receiver_| with the module thread only around the time the decoder thread is started/stopped.
> * Notifies the receiver of start/stop events of the decoder thread.
> * Changed the decoder thread to use the new PlatformThread callback type.
>
> BUG=webrtc:7361, 695438
>
> Review-Url: https://codereview.webrtc.org/2764573002
> Cr-Commit-Position: refs/heads/master@{#17527}
> Committed: https://chromium.googlesource.com/external/webrtc/+/e3aa88bbd5accadec73fa7e38584dfbf6aabe8a9
TBR=sakal@webrtc.org,mflodman@webrtc.org,stefan@webrtc.org,tommi@webrtc.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=webrtc:7361, 695438
Review-Url: https://codereview.webrtc.org/2792033003
Cr-Commit-Position: refs/heads/master@{#17530}
2017-04-04 07:16:21 -07:00
|
|
|
RTC_CHECK_EQ(height, slice_height);
|
2017-02-23 07:11:32 -08:00
|
|
|
// Duplicate the last chroma rows.
|
|
|
|
|
uint8_t* u_last_row_ptr = i420_buffer->MutableDataU() +
|
|
|
|
|
chroma_height * i420_buffer->StrideU();
|
|
|
|
|
memcpy(u_last_row_ptr, u_last_row_ptr - i420_buffer->StrideU(),
|
|
|
|
|
i420_buffer->StrideU());
|
|
|
|
|
uint8_t* v_last_row_ptr = i420_buffer->MutableDataV() +
|
|
|
|
|
chroma_height * i420_buffer->StrideV();
|
|
|
|
|
memcpy(v_last_row_ptr, v_last_row_ptr - i420_buffer->StrideV(),
|
|
|
|
|
i420_buffer->StrideV());
|
|
|
|
|
}
|
2015-02-18 18:42:55 +00:00
|
|
|
} else {
|
|
|
|
|
// All other supported formats are nv12.
|
2015-09-30 16:06:37 +02:00
|
|
|
const uint8_t* y_ptr = payload;
|
|
|
|
|
const uint8_t* uv_ptr = y_ptr + stride * slice_height;
|
2016-09-14 05:45:06 -07:00
|
|
|
libyuv::NV12ToI420(y_ptr, stride, uv_ptr, stride,
|
|
|
|
|
i420_buffer->MutableDataY(), i420_buffer->StrideY(),
|
|
|
|
|
i420_buffer->MutableDataU(), i420_buffer->StrideU(),
|
|
|
|
|
i420_buffer->MutableDataV(), i420_buffer->StrideV(),
|
|
|
|
|
width, height);
|
2015-02-18 18:42:55 +00:00
|
|
|
}
|
2016-09-14 05:45:06 -07:00
|
|
|
frame_buffer = i420_buffer;
|
|
|
|
|
|
2015-10-03 02:08:00 -07:00
|
|
|
// Return output byte buffer back to codec.
|
2017-12-08 11:05:22 +01:00
|
|
|
Java_MediaCodecVideoDecoder_returnDecodedOutputBuffer(
|
2017-12-20 15:12:10 +01:00
|
|
|
jni, j_media_codec_video_decoder_, output_buffer_index);
|
2015-10-03 02:08:00 -07:00
|
|
|
if (CheckException(jni)) {
|
2015-11-19 10:43:36 +01:00
|
|
|
ALOGE << "returnDecodedOutputBuffer error";
|
2015-10-03 02:08:00 -07:00
|
|
|
return false;
|
|
|
|
|
}
|
2015-02-18 18:42:55 +00:00
|
|
|
}
|
2016-02-04 11:47:12 -08:00
|
|
|
if (frames_decoded_ < frames_decoded_logged_) {
|
2016-02-01 13:17:18 -08:00
|
|
|
ALOGD << "Decoder frame out # " << frames_decoded_ << ". " << width << " x "
|
|
|
|
|
<< height << ". Color: " << color_format
|
|
|
|
|
<< ". TS: " << presentation_timestamps_ms
|
2017-12-12 12:52:54 +01:00
|
|
|
<< ". DecTime: " << static_cast<int>(decode_time_ms)
|
|
|
|
|
<< ". DelayTime: " << static_cast<int>(frame_delayed_ms);
|
2015-10-28 10:30:32 -07:00
|
|
|
}
|
2015-02-18 18:42:55 +00:00
|
|
|
|
|
|
|
|
// Calculate and print decoding statistics - every 3 seconds.
|
|
|
|
|
frames_decoded_++;
|
|
|
|
|
current_frames_++;
|
2015-11-19 10:43:36 +01:00
|
|
|
current_decoding_time_ms_ += decode_time_ms;
|
2016-02-05 14:05:08 -08:00
|
|
|
current_delay_time_ms_ += frame_delayed_ms;
|
2016-05-10 16:31:47 +02:00
|
|
|
int statistic_time_ms = rtc::TimeMillis() - start_time_ms_;
|
2015-02-18 18:42:55 +00:00
|
|
|
if (statistic_time_ms >= kMediaCodecStatisticsIntervalMs &&
|
|
|
|
|
current_frames_ > 0) {
|
2016-02-01 13:17:18 -08:00
|
|
|
int current_bitrate = current_bytes_ * 8 / statistic_time_ms;
|
|
|
|
|
int current_fps =
|
|
|
|
|
(current_frames_ * 1000 + statistic_time_ms / 2) / statistic_time_ms;
|
2016-02-05 14:05:08 -08:00
|
|
|
ALOGD << "Frames decoded: " << frames_decoded_
|
|
|
|
|
<< ". Received: " << frames_received_
|
2016-02-01 13:17:18 -08:00
|
|
|
<< ". Bitrate: " << current_bitrate << " kbps"
|
|
|
|
|
<< ". Fps: " << current_fps
|
|
|
|
|
<< ". DecTime: " << (current_decoding_time_ms_ / current_frames_)
|
2016-02-05 14:05:08 -08:00
|
|
|
<< ". DelayTime: " << (current_delay_time_ms_ / current_frames_)
|
2015-10-07 16:51:02 -07:00
|
|
|
<< " for last " << statistic_time_ms << " ms.";
|
2016-05-10 16:31:47 +02:00
|
|
|
start_time_ms_ = rtc::TimeMillis();
|
2015-02-18 18:42:55 +00:00
|
|
|
current_frames_ = 0;
|
|
|
|
|
current_bytes_ = 0;
|
|
|
|
|
current_decoding_time_ms_ = 0;
|
2016-02-05 14:05:08 -08:00
|
|
|
current_delay_time_ms_ = 0;
|
2015-02-18 18:42:55 +00:00
|
|
|
}
|
|
|
|
|
|
2016-05-23 23:35:54 -07:00
|
|
|
// If the frame was dropped, frame_buffer is left as nullptr.
|
|
|
|
|
if (frame_buffer) {
|
2017-08-28 16:24:06 -07:00
|
|
|
VideoFrame decoded_frame(frame_buffer, 0, 0, kVideoRotation_0);
|
2016-05-23 23:35:54 -07:00
|
|
|
decoded_frame.set_timestamp(output_timestamps_ms);
|
|
|
|
|
decoded_frame.set_ntp_time_ms(output_ntp_timestamps_ms);
|
|
|
|
|
|
2018-06-21 10:17:24 +02:00
|
|
|
absl::optional<uint8_t> qp = pending_frame_qps_.front();
|
2017-02-17 03:26:10 -08:00
|
|
|
pending_frame_qps_.pop_front();
|
2017-11-16 10:52:24 +01:00
|
|
|
callback_->Decoded(decoded_frame, decode_time_ms, qp);
|
2015-02-18 18:42:55 +00:00
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int32_t MediaCodecVideoDecoder::RegisterDecodeCompleteCallback(
|
|
|
|
|
DecodedImageCallback* callback) {
|
|
|
|
|
callback_ = callback;
|
|
|
|
|
return WEBRTC_VIDEO_CODEC_OK;
|
|
|
|
|
}
|
|
|
|
|
|
Revert of Deliver video frames on Android, on the decode thread. (patchset #7 id:120001 of https://codereview.webrtc.org/2764573002/ )
Reason for revert:
Breaks Chrome FYI Android bots.
See:
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus9%29/builds/20418
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus6%29/builds/14724
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28L%20Nexus5%29/builds/20133
https://build.chromium.org/p/chromium.webrtc.fyi/builders/Android%20Tests%20%28dbg%29%20%28K%20Nexus5%29/builds/15111
Original issue's description:
> Deliver video frames on Android, on the decode thread.
>
> VideoCoding
> * Adding a method for polling for frames on Android only until the capture implementation takes care of this (longer term plan).
>
> CodecDatabase
> * Add an accessor for the current decoder
> * Use std::unique_ptr<> for ownership.
> * Remove "Release()" and "ReleaseDecoder()". Instead just delete.
> * Remove |friend| relationship between CodecDatabase and VCMGenericDecoder.
>
> VCMDecodedFrameCallback
> * DCHECKs for thread correctness.
> * Remove |lock_| now that a threading model has been established and verified.
>
> VCMGenericDecoder
> * All methods now have thread checks.
> * Variable access associated with thread checkers.
>
> VideoReceiver
> * Added two notification methods, DecoderThreadStarting() and DecoderThreadStopped()
> * Allows us to establish a period when the decoder thread is not running and it is safe to modify variables such as callbacks, that are only read when the decoder thread is running.
> * Allows us to DCHECK thread guarantees.
> * Allows synchronizing callbacks from the module process thread and have them only active while the decoder thread is running.
> * The above, allows us to establish two modes for the thread, single-threaded-mutable and multi-threaded-const.
> * Using that knowledge, we can remove |receive_crit_| as well as locking for a number of member variables.
>
> MediaCodecVideoDecoder
> * Removed frame polling code from this class, since this is now done from the root thread function in VideoReceiveStream.
>
> VideoReceiveStream
> * On Android: Polls for decoded frames every 10ms (same interval as previously in MediaCodecVideoDecoder)
> * [Un]Registers the |video_receiver_| with the module thread only around the time the decoder thread is started/stopped.
> * Notifies the receiver of start/stop events of the decoder thread.
> * Changed the decoder thread to use the new PlatformThread callback type.
>
> BUG=webrtc:7361, 695438
>
> Review-Url: https://codereview.webrtc.org/2764573002
> Cr-Commit-Position: refs/heads/master@{#17527}
> Committed: https://chromium.googlesource.com/external/webrtc/+/e3aa88bbd5accadec73fa7e38584dfbf6aabe8a9
TBR=sakal@webrtc.org,mflodman@webrtc.org,stefan@webrtc.org,tommi@webrtc.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=webrtc:7361, 695438
Review-Url: https://codereview.webrtc.org/2792033003
Cr-Commit-Position: refs/heads/master@{#17530}
2017-04-04 07:16:21 -07:00
|
|
|
void MediaCodecVideoDecoder::OnMessage(rtc::Message* msg) {
|
|
|
|
|
JNIEnv* jni = AttachCurrentThreadIfNeeded();
|
|
|
|
|
ScopedLocalRefFrame local_ref_frame(jni);
|
|
|
|
|
if (!inited_) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// We only ever send one message to |this| directly (not through a Bind()'d
|
|
|
|
|
// functor), so expect no ID/data.
|
|
|
|
|
RTC_CHECK(!msg->message_id) << "Unexpected message!";
|
|
|
|
|
RTC_CHECK(!msg->pdata) << "Unexpected message!";
|
|
|
|
|
CheckOnCodecThread();
|
|
|
|
|
|
|
|
|
|
if (!DeliverPendingOutputs(jni, 0)) {
|
|
|
|
|
ALOGE << "OnMessage: DeliverPendingOutputs error";
|
|
|
|
|
ProcessHWErrorOnCodecThread();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
codec_thread_->PostDelayed(RTC_FROM_HERE, kMediaCodecPollMs, this);
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-15 06:28:36 -08:00
|
|
|
MediaCodecVideoDecoderFactory::MediaCodecVideoDecoderFactory()
|
|
|
|
|
: egl_context_(nullptr) {
|
2015-10-07 16:51:02 -07:00
|
|
|
ALOGD << "MediaCodecVideoDecoderFactory ctor";
|
2015-02-18 18:42:55 +00:00
|
|
|
JNIEnv* jni = AttachCurrentThreadIfNeeded();
|
|
|
|
|
ScopedLocalRefFrame local_ref_frame(jni);
|
2015-02-23 17:44:27 +00:00
|
|
|
supported_codec_types_.clear();
|
|
|
|
|
|
2017-12-08 11:05:22 +01:00
|
|
|
if (Java_MediaCodecVideoDecoder_isVp8HwSupported(jni) &&
|
|
|
|
|
!CheckException(jni)) {
|
2015-10-07 16:51:02 -07:00
|
|
|
ALOGD << "VP8 HW Decoder supported.";
|
2015-02-23 17:44:27 +00:00
|
|
|
supported_codec_types_.push_back(kVideoCodecVP8);
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-08 11:05:22 +01:00
|
|
|
if (Java_MediaCodecVideoDecoder_isVp9HwSupported(jni) &&
|
|
|
|
|
!CheckException(jni)) {
|
2015-11-10 10:25:40 -08:00
|
|
|
ALOGD << "VP9 HW Decoder supported.";
|
|
|
|
|
supported_codec_types_.push_back(kVideoCodecVP9);
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-08 11:05:22 +01:00
|
|
|
if (Java_MediaCodecVideoDecoder_isH264HwSupported(jni) &&
|
|
|
|
|
!CheckException(jni)) {
|
2015-10-07 16:51:02 -07:00
|
|
|
ALOGD << "H264 HW Decoder supported.";
|
2015-02-23 17:44:27 +00:00
|
|
|
supported_codec_types_.push_back(kVideoCodecH264);
|
|
|
|
|
}
|
2015-02-18 18:42:55 +00:00
|
|
|
}
|
|
|
|
|
|
2015-09-01 15:04:13 -07:00
|
|
|
MediaCodecVideoDecoderFactory::~MediaCodecVideoDecoderFactory() {
|
2015-10-07 16:51:02 -07:00
|
|
|
ALOGD << "MediaCodecVideoDecoderFactory dtor";
|
2016-02-15 06:28:36 -08:00
|
|
|
if (egl_context_) {
|
|
|
|
|
JNIEnv* jni = AttachCurrentThreadIfNeeded();
|
|
|
|
|
jni->DeleteGlobalRef(egl_context_);
|
|
|
|
|
}
|
2015-09-01 15:04:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MediaCodecVideoDecoderFactory::SetEGLContext(JNIEnv* jni,
|
2016-02-15 06:28:36 -08:00
|
|
|
jobject egl_context) {
|
2015-10-07 16:51:02 -07:00
|
|
|
ALOGD << "MediaCodecVideoDecoderFactory::SetEGLContext";
|
2016-02-18 11:35:48 +01:00
|
|
|
if (egl_context_) {
|
|
|
|
|
jni->DeleteGlobalRef(egl_context_);
|
|
|
|
|
egl_context_ = nullptr;
|
|
|
|
|
}
|
2016-02-15 06:28:36 -08:00
|
|
|
egl_context_ = jni->NewGlobalRef(egl_context);
|
|
|
|
|
if (CheckException(jni)) {
|
|
|
|
|
ALOGE << "error calling NewGlobalRef for EGL Context.";
|
2015-09-01 15:04:13 -07:00
|
|
|
}
|
|
|
|
|
}
|
2015-02-18 18:42:55 +00:00
|
|
|
|
2017-08-28 16:24:06 -07:00
|
|
|
VideoDecoder* MediaCodecVideoDecoderFactory::CreateVideoDecoder(
|
2015-02-23 17:44:27 +00:00
|
|
|
VideoCodecType type) {
|
|
|
|
|
if (supported_codec_types_.empty()) {
|
2017-12-12 12:52:54 +01:00
|
|
|
ALOGW << "No HW video decoder for type " << static_cast<int>(type);
|
2016-01-27 15:25:46 +01:00
|
|
|
return nullptr;
|
2015-02-18 18:42:55 +00:00
|
|
|
}
|
2015-09-01 15:04:13 -07:00
|
|
|
for (VideoCodecType codec_type : supported_codec_types_) {
|
|
|
|
|
if (codec_type == type) {
|
2017-12-12 12:52:54 +01:00
|
|
|
ALOGD << "Create HW video decoder for type " << static_cast<int>(type);
|
2017-03-30 01:08:36 -07:00
|
|
|
JNIEnv* jni = AttachCurrentThreadIfNeeded();
|
|
|
|
|
ScopedLocalRefFrame local_ref_frame(jni);
|
|
|
|
|
return new MediaCodecVideoDecoder(jni, type, egl_context_);
|
2015-02-23 17:44:27 +00:00
|
|
|
}
|
|
|
|
|
}
|
2017-12-12 12:52:54 +01:00
|
|
|
ALOGW << "Can not find HW video decoder for type " << static_cast<int>(type);
|
2016-01-27 15:25:46 +01:00
|
|
|
return nullptr;
|
2015-02-18 18:42:55 +00:00
|
|
|
}
|
|
|
|
|
|
2017-08-28 16:24:06 -07:00
|
|
|
void MediaCodecVideoDecoderFactory::DestroyVideoDecoder(VideoDecoder* decoder) {
|
2015-10-07 16:51:02 -07:00
|
|
|
ALOGD << "Destroy video decoder.";
|
2015-02-18 18:42:55 +00:00
|
|
|
delete decoder;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-08 11:05:22 +01:00
|
|
|
bool MediaCodecVideoDecoderFactory::IsH264HighProfileSupported(JNIEnv* env) {
|
|
|
|
|
return Java_MediaCodecVideoDecoder_isH264HighProfileHwSupported(env);
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-18 16:01:11 +01:00
|
|
|
const char* MediaCodecVideoDecoder::ImplementationName() const {
|
|
|
|
|
return "MediaCodec";
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-28 16:24:06 -07:00
|
|
|
} // namespace jni
|
|
|
|
|
} // namespace webrtc
|