| Index: media/cast/sender/size_adaptable_video_encoder_base.h
|
| diff --git a/media/cast/sender/size_adaptable_video_encoder_base.h b/media/cast/sender/size_adaptable_video_encoder_base.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..6d33b55333c8a863ff61704025e66228222c3dc8
|
| --- /dev/null
|
| +++ b/media/cast/sender/size_adaptable_video_encoder_base.h
|
| @@ -0,0 +1,119 @@
|
| +// Copyright 2015 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#ifndef MEDIA_CAST_SENDER_SIZE_ADAPTABLE_VIDEO_ENCODER_BASE_H_
|
| +#define MEDIA_CAST_SENDER_SIZE_ADAPTABLE_VIDEO_ENCODER_BASE_H_
|
| +
|
| +#include "base/memory/ref_counted.h"
|
| +#include "base/memory/scoped_ptr.h"
|
| +#include "base/memory/weak_ptr.h"
|
| +#include "media/cast/cast_config.h"
|
| +#include "media/cast/cast_environment.h"
|
| +#include "media/cast/sender/video_encoder.h"
|
| +#include "ui/gfx/geometry/size.h"
|
| +
|
| +namespace media {
|
| +namespace cast {
|
| +
|
| +// Creates and owns a VideoEncoder instance. The owned instance is an
|
| +// implementation that does not support changing frame sizes, and so
|
| +// SizeAdaptableVideoEncoderBase acts as a proxy to automatically detect when
|
| +// the owned instance should be replaced with one that can handle the new frame
|
| +// size.
|
| +class SizeAdaptableVideoEncoderBase : public VideoEncoder {
|
| + public:
|
| + SizeAdaptableVideoEncoderBase(
|
| + const scoped_refptr<CastEnvironment>& cast_environment,
|
| + const VideoSenderConfig& video_config,
|
| + const StatusChangeCallback& status_change_cb);
|
| +
|
| + ~SizeAdaptableVideoEncoderBase() override;
|
| +
|
| + // VideoEncoder implementation.
|
| + bool EncodeVideoFrame(
|
| + const scoped_refptr<media::VideoFrame>& video_frame,
|
| + const base::TimeTicks& reference_time,
|
| + const FrameEncodedCallback& frame_encoded_callback) override;
|
| + void SetBitRate(int new_bit_rate) override;
|
| + void GenerateKeyFrame() override;
|
| + void LatestFrameIdToReference(uint32 frame_id) override;
|
| + scoped_ptr<VideoFrameFactory> CreateVideoFrameFactory() override;
|
| + void EmitFrames() override;
|
| +
|
| + protected:
|
| + // Accessors for subclasses.
|
| + CastEnvironment* cast_environment() const {
|
| + return cast_environment_.get();
|
| + }
|
| + const VideoSenderConfig& video_config() const {
|
| + return video_config_;
|
| + }
|
| + const gfx::Size& next_encoder_frame_size() const {
|
| + return next_encoder_frame_size_;
|
| + }
|
| + uint32 last_frame_id() const {
|
| + return last_frame_id_;
|
| + }
|
| +
|
| + // Returns a callback that calls OnEncoderStatusChange().
|
| + StatusChangeCallback CreateEncoderStatusChangeCallback();
|
| +
|
| + // Overridden by subclasses to provide the underlying encoder implementation.
|
| + virtual scoped_ptr<VideoEncoder> CreateReplacementEncoder() = 0;
|
| +
|
| + // Overridden by subclasses to perform additional steps when
|
| + // |replacement_encoder| becomes the active encoder.
|
| + virtual void OnEncoderReplaced(VideoEncoder* replacement_encoder);
|
| +
|
| + // Overridden by subclasses to perform additional steps before/after the
|
| + // current encoder is destroyed.
|
| + virtual void DestroyCurrentEncoder();
|
| +
|
| + private:
|
| + // Create and initialize a replacement video encoder, if this not already
|
| + // in-progress. The replacement will call back to OnEncoderStatusChange()
|
| + // with success/fail status, and |current_encoder_| will be set there.
|
| + void MaybeSpawnReplacementEncoder(const gfx::Size& size_needed);
|
| +
|
| + // Called when a status change is received from an encoder.
|
| + void OnEncoderStatusChange(OperationalStatus status);
|
| +
|
| + // Called by the |current_encoder_| with the next EncodedFrame.
|
| + void OnEncodedVideoFrame(const FrameEncodedCallback& frame_encoded_callback,
|
| + scoped_ptr<EncodedFrame> encoded_frame);
|
| +
|
| + const scoped_refptr<CastEnvironment> cast_environment_;
|
| +
|
| + // This is not const since |video_config_.starting_bitrate| is modified by
|
| + // SetBitRate(), for when a replacement encoder is spawned.
|
| + VideoSenderConfig video_config_;
|
| +
|
| + // Run whenever the underlying encoder reports a status change.
|
| + const StatusChangeCallback status_change_cb_;
|
| +
|
| + // The underlying platform video encoder and current frame size.
|
| + scoped_ptr<VideoEncoder> current_encoder_;
|
| + gfx::Size current_encoder_frame_size_;
|
| +
|
| + // The replacement encoder currently being initialized, but not yet ready for
|
| + // use.
|
| + scoped_ptr<VideoEncoder> next_encoder_;
|
| + gfx::Size next_encoder_frame_size_;
|
| +
|
| + // The number of frames in |current_encoder_|'s pipeline.
|
| + int frames_in_encoder_;
|
| +
|
| + // The ID of the last frame that was emitted from |current_encoder_|.
|
| + uint32 last_frame_id_;
|
| +
|
| + // NOTE: Weak pointers must be invalidated before all other member variables.
|
| + base::WeakPtrFactory<SizeAdaptableVideoEncoderBase> weak_factory_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(SizeAdaptableVideoEncoderBase);
|
| +};
|
| +
|
| +} // namespace cast
|
| +} // namespace media
|
| +
|
| +#endif // MEDIA_CAST_SENDER_SIZE_ADAPTABLE_VIDEO_ENCODER_BASE_H_
|
|
|