Refactor WebsiteSettings to operate on a SecurityInfo
[chromium-blink-merge.git] / media / cast / sender / video_encoder.h
blobff73c550616bea33d1ebcd6aaf32feeef4ee3f2a
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef MEDIA_CAST_SENDER_VIDEO_ENCODER_H_
6 #define MEDIA_CAST_SENDER_VIDEO_ENCODER_H_
8 #include "base/callback.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/time/time.h"
12 #include "media/base/video_frame.h"
13 #include "media/cast/cast_config.h"
14 #include "media/cast/cast_environment.h"
15 #include "media/cast/sender/sender_encoded_frame.h"
16 #include "media/cast/sender/video_frame_factory.h"
18 namespace media {
19 namespace cast {
21 // All these functions are called from the main cast thread.
22 class VideoEncoder {
23 public:
24 // Callback used to deliver an encoded frame on the Cast MAIN thread.
25 using FrameEncodedCallback =
26 base::Callback<void(scoped_ptr<SenderEncodedFrame>)>;
28 // Creates a VideoEncoder instance from the given |video_config| and based on
29 // the current platform's hardware/library support; or null if no
30 // implementation will suffice. The instance will run |status_change_cb| at
31 // some point in the future to indicate initialization success/failure.
33 // All VideoEncoder instances returned by this function support encoding
34 // sequences of differently-size VideoFrames.
36 // TODO(miu): Remove the CreateVEA callbacks. http://crbug.com/454029
37 static scoped_ptr<VideoEncoder> Create(
38 const scoped_refptr<CastEnvironment>& cast_environment,
39 const VideoSenderConfig& video_config,
40 const StatusChangeCallback& status_change_cb,
41 const CreateVideoEncodeAcceleratorCallback& create_vea_cb,
42 const CreateVideoEncodeMemoryCallback& create_video_encode_memory_cb);
44 virtual ~VideoEncoder() {}
46 // If true is returned, the Encoder has accepted the request and will process
47 // it asynchronously, running |frame_encoded_callback| on the MAIN
48 // CastEnvironment thread with the result. If false is returned, nothing
49 // happens and the callback will not be run.
50 virtual bool EncodeVideoFrame(
51 const scoped_refptr<media::VideoFrame>& video_frame,
52 const base::TimeTicks& reference_time,
53 const FrameEncodedCallback& frame_encoded_callback) = 0;
55 // Inform the encoder about the new target bit rate.
56 virtual void SetBitRate(int new_bit_rate) = 0;
58 // Inform the encoder to encode the next frame as a key frame.
59 virtual void GenerateKeyFrame() = 0;
61 // Inform the encoder to only reference frames older or equal to frame_id;
62 virtual void LatestFrameIdToReference(uint32 frame_id) = 0;
64 // Creates a |VideoFrameFactory| object to vend |VideoFrame| object with
65 // encoder affinity (defined as offering some sort of performance benefit).
66 // This is an optional capability and by default returns null.
67 virtual scoped_ptr<VideoFrameFactory> CreateVideoFrameFactory();
69 // Instructs the encoder to finish and emit all frames that have been
70 // submitted for encoding. An encoder may hold a certain number of frames for
71 // analysis. Under certain network conditions, particularly when there is
72 // network congestion, it is necessary to flush out of the encoder all
73 // submitted frames so that eventually new frames may be encoded. Like
74 // EncodeVideoFrame(), the encoder will process this request asynchronously.
75 virtual void EmitFrames();
78 } // namespace cast
79 } // namespace media
81 #endif // MEDIA_CAST_SENDER_VIDEO_ENCODER_H_