Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(141)

Unified Diff: webrtc/video/vie_encoder.h

Issue 2060403002: Add task queue to Call. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@move_getpadding
Patch Set: Fix audio thread check when adding audio to bitrateallocator. Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webrtc/video/vie_encoder.h
diff --git a/webrtc/video/vie_encoder.h b/webrtc/video/vie_encoder.h
index f3f8340c28e41724b943e6ba8cf1dccbd293239a..42fe03b18856a5834644ff8ca342ec1556ba349b 100644
--- a/webrtc/video/vie_encoder.h
+++ b/webrtc/video/vie_encoder.h
@@ -16,81 +16,71 @@
#include <vector>
#include "webrtc/base/criticalsection.h"
-#include "webrtc/base/scoped_ref_ptr.h"
-#include "webrtc/base/thread_annotations.h"
+#include "webrtc/base/event.h"
+#include "webrtc/base/sequenced_task_checker.h"
+#include "webrtc/base/task_queue.h"
+#include "webrtc/call.h"
#include "webrtc/common_types.h"
-#include "webrtc/video_encoder.h"
#include "webrtc/media/base/videosinkinterface.h"
-#include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
#include "webrtc/modules/video_coding/include/video_coding_defines.h"
#include "webrtc/modules/video_coding/video_coding_impl.h"
#include "webrtc/modules/video_processing/include/video_processing.h"
+#include "webrtc/system_wrappers/include/atomic32.h"
+#include "webrtc/video/overuse_frame_detector.h"
+#include "webrtc/video_encoder.h"
+#include "webrtc/video_send_stream.h"
#include "webrtc/typedefs.h"
namespace webrtc {
-class Config;
-class EncodedImageCallback;
-class OveruseFrameDetector;
-class PacedSender;
class ProcessThread;
class SendStatisticsProxy;
-class ViEBitrateObserver;
-class ViEEffectFilter;
-class VideoEncoder;
// VieEncoder represent a video encoder that accepts raw video frames as input
// and produces an encoded bit stream.
// Usage:
-// 1. Instantiate
-// 2. Call Init
-// 3. Call RegisterExternalEncoder if available.
-// 4. Call SetEncoder with the codec settings and the object that shall receive
-// the encoded bit stream.
-// 5. For each available raw video frame call EncodeVideoFrame.
-class ViEEncoder : public EncodedImageCallback,
- public VCMSendStatisticsCallback {
+// Instantiate.
+// Call SetStartRate and SetSink.
+// Call ConfigureEncoder with the codec settings.
+// Provide frames to encode by calling IncomingCapturedFrame.
+// Call Stop() when done.
+class ViEEncoder : public VideoCaptureInput,
+ public EncodedImageCallback,
+ public VCMSendStatisticsCallback,
+ public CpuOveruseObserver {
public:
- friend class ViEBitrateObserver;
-
ViEEncoder(uint32_t number_of_cores,
- ProcessThread* module_process_thread,
SendStatisticsProxy* stats_proxy,
- OveruseFrameDetector* overuse_detector,
- EncodedImageCallback* sink);
+ const webrtc::VideoSendStream::Config::EncoderSettings& settings,
+ rtc::VideoSinkInterface<VideoFrame>* pre_encode_callback,
+ LoadObserver* overuse_callback,
+ EncodedFrameObserver* encoder_timing);
~ViEEncoder();
+ // RegisterProcessThread register |module_process_thread| with those objects
+ // that use it. Registration has to happen on the thread where
+ // |module_process_thread| was created (libjingle's worker thread).
+ // TODO(perkj): Replace the use of |module_process_thread| with a TaskQueue.
+ void RegisterProcessThread(ProcessThread* module_process_thread);
+ void DeRegisterProcessThread();
- vcm::VideoSender* video_sender();
+ void SetSink(EncodedImageCallback* sink);
- // Returns the id of the owning channel.
- int Owner() const;
+ // TODO(perkj): Can we remove VideoCodec.startBitrate ?
+ void SetStartBitrate(int start_bitrate_bps);
- // Codec settings.
- int32_t RegisterExternalEncoder(VideoEncoder* encoder,
- uint8_t pl_type,
- bool internal_source);
- int32_t DeRegisterExternalEncoder(uint8_t pl_type);
- void SetEncoder(const VideoCodec& video_codec,
- size_t max_data_payload_length);
-
- void EncodeVideoFrame(const VideoFrame& video_frame);
- void SendKeyFrame();
+ void ConfigureEncoder(const VideoEncoderConfig& config,
+ size_t max_data_payload_length);
- // Returns the time when the encoder last received an input frame or produced
- // an encoded frame.
- int64_t time_of_last_frame_activity_ms();
+ // Permanently stop encoding. After this method has returned, it is
+ // guaranteed that no encoded frames will be delivered to the sink.
+ void Stop();
+ // Implements VideoCaptureInput.
+ // TODO(perkj): Refactor ViEEncoder to inherit rtc::VideoSink instead of
+ // VideoCaptureInput.
+ void IncomingCapturedFrame(const VideoFrame& video_frame) override;
- // Implements EncodedImageCallback.
- EncodedImageCallback::Result OnEncodedImage(
- const EncodedImage& encoded_image,
- const CodecSpecificInfo* codec_specific_info,
- const RTPFragmentationHeader* fragmentation) override;
-
- // Implements VideoSendStatisticsCallback.
- void SendStatistics(uint32_t bit_rate,
- uint32_t frame_rate,
- const std::string& encoder_name) override;
+ void SendKeyFrame();
// virtual to test EncoderStateFeedback with mocks.
virtual void OnReceivedIntraFrameRequest(size_t stream_index);
@@ -102,37 +92,69 @@ class ViEEncoder : public EncodedImageCallback,
int64_t round_trip_time_ms);
private:
- bool EncoderPaused() const EXCLUSIVE_LOCKS_REQUIRED(data_cs_);
- void TraceFrameDropStart() EXCLUSIVE_LOCKS_REQUIRED(data_cs_);
- void TraceFrameDropEnd() EXCLUSIVE_LOCKS_REQUIRED(data_cs_);
+ class EncodeTask;
- const uint32_t number_of_cores_;
- EncodedImageCallback* const sink_;
+ void ConfigureEncoderInternal(const VideoCodec& video_codec,
+ size_t max_data_payload_length);
- const std::unique_ptr<VideoProcessing> vp_;
- vcm::VideoSender video_sender_;
+ // Implements VideoSendStatisticsCallback.
+ void SendStatistics(uint32_t bit_rate,
+ uint32_t frame_rate,
+ const std::string& encoder_name) override;
- rtc::CriticalSection data_cs_;
+ void EncodeVideoFrame(const VideoFrame& frame);
- SendStatisticsProxy* const stats_proxy_;
- OveruseFrameDetector* const overuse_detector_;
+ // Implements EncodedImageCallback.
+ EncodedImageCallback::Result OnEncodedImage(
+ const EncodedImage& encoded_image,
+ const CodecSpecificInfo* codec_specific_info,
+ const RTPFragmentationHeader* fragmentation) override;
- // The time we last received an input frame or encoded frame. This is used to
- // track when video is stopped long enough that we also want to stop sending
- // padding.
- int64_t time_of_last_frame_activity_ms_ GUARDED_BY(data_cs_);
- VideoCodec encoder_config_ GUARDED_BY(data_cs_);
- uint32_t last_observed_bitrate_bps_ GUARDED_BY(data_cs_);
- bool encoder_paused_and_dropped_frame_ GUARDED_BY(data_cs_);
+ // webrtc::CpuOveruseObserver implementation.
+ void OveruseDetected() override;
+ void NormalUsage() override;
- ProcessThread* module_process_thread_;
+ bool EncoderPaused() const;
+ void TraceFrameDropStart();
+ void TraceFrameDropEnd();
+
+ rtc::Event shutdown_event_;
+
+ const uint32_t number_of_cores_;
+ EncodedImageCallback* sink_;
+ const VideoSendStream::Config::EncoderSettings settings_;
- bool has_received_sli_ GUARDED_BY(data_cs_);
- uint8_t picture_id_sli_ GUARDED_BY(data_cs_);
- bool has_received_rpsi_ GUARDED_BY(data_cs_);
- uint64_t picture_id_rpsi_ GUARDED_BY(data_cs_);
+ const std::unique_ptr<VideoProcessing> vp_;
+ vcm::VideoSender video_sender_ ACCESS_ON(&encoder_queue_);
+ OveruseFrameDetector overuse_detector_;
+ LoadObserver* const load_observer_ ACCESS_ON(&module_process_thread_checker_);
- bool video_suspended_ GUARDED_BY(data_cs_);
+ SendStatisticsProxy* const stats_proxy_;
+ rtc::VideoSinkInterface<VideoFrame>* const pre_encode_callback_;
+ ProcessThread* module_process_thread_;
+ rtc::ThreadChecker module_process_thread_checker_;
+
+ VideoCodec encoder_config_ ACCESS_ON(&encoder_queue_);
+
+ int encoder_start_bitrate_bps_ ACCESS_ON(&encoder_queue_);
+ uint32_t last_observed_bitrate_bps_ ACCESS_ON(&encoder_queue_);
+ bool encoder_paused_and_dropped_frame_ ACCESS_ON(&encoder_queue_);
+ bool has_received_sli_ ACCESS_ON(&encoder_queue_);
+ uint8_t picture_id_sli_ ACCESS_ON(&encoder_queue_);
+ bool has_received_rpsi_ ACCESS_ON(&encoder_queue_);
+ uint64_t picture_id_rpsi_ ACCESS_ON(&encoder_queue_);
+ Clock* const clock_;
+
+ rtc::RaceChecker incoming_frame_race_checker_;
+ Atomic32 posted_frames_waiting_for_encode_;
+ // Used to make sure incoming time stamp is increasing for every frame.
+ int64_t last_captured_timestamp_ GUARDED_BY(incoming_frame_race_checker_);
+ // Delta used for translating between NTP and internal timestamps.
+ const int64_t delta_ntp_internal_ms_;
+
+ // All public methods are proxied to |encoder_queue_|. It must must be
+ // destroyed first to make sure no tasks are run that use other members.
+ rtc::TaskQueue encoder_queue_;
};
} // namespace webrtc

Powered by Google App Engine
This is Rietveld 408576698