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/video_frame_factory.h"
20 // All these functions are called from the main cast thread.
23 typedef base::Callback
<void(scoped_ptr
<EncodedFrame
>)> FrameEncodedCallback
;
25 // Creates a VideoEncoder instance from the given |video_config| and based on
26 // the current platform's hardware/library support; or null if no
27 // implementation will suffice. The instance will run |status_change_cb| at
28 // some point in the future to indicate initialization success/failure.
30 // All VideoEncoder instances returned by this function support encoding
31 // sequences of differently-size VideoFrames.
33 // TODO(miu): Remove the CreateVEA callbacks. http://crbug.com/454029
34 static scoped_ptr
<VideoEncoder
> Create(
35 const scoped_refptr
<CastEnvironment
>& cast_environment
,
36 const VideoSenderConfig
& video_config
,
37 const StatusChangeCallback
& status_change_cb
,
38 const CreateVideoEncodeAcceleratorCallback
& create_vea_cb
,
39 const CreateVideoEncodeMemoryCallback
& create_video_encode_memory_cb
);
41 virtual ~VideoEncoder() {}
43 // If true is returned, the Encoder has accepted the request and will process
44 // it asynchronously, running |frame_encoded_callback| on the MAIN
45 // CastEnvironment thread with the result. If false is returned, nothing
46 // happens and the callback will not be run.
47 virtual bool EncodeVideoFrame(
48 const scoped_refptr
<media::VideoFrame
>& video_frame
,
49 const base::TimeTicks
& reference_time
,
50 const FrameEncodedCallback
& frame_encoded_callback
) = 0;
52 // Inform the encoder about the new target bit rate.
53 virtual void SetBitRate(int new_bit_rate
) = 0;
55 // Inform the encoder to encode the next frame as a key frame.
56 virtual void GenerateKeyFrame() = 0;
58 // Inform the encoder to only reference frames older or equal to frame_id;
59 virtual void LatestFrameIdToReference(uint32 frame_id
) = 0;
61 // Creates a |VideoFrameFactory| object to vend |VideoFrame| object with
62 // encoder affinity (defined as offering some sort of performance benefit).
63 // This is an optional capability and by default returns null.
64 virtual scoped_ptr
<VideoFrameFactory
> CreateVideoFrameFactory();
66 // Instructs the encoder to finish and emit all frames that have been
67 // submitted for encoding. An encoder may hold a certain number of frames for
68 // analysis. Under certain network conditions, particularly when there is
69 // network congestion, it is necessary to flush out of the encoder all
70 // submitted frames so that eventually new frames may be encoded. Like
71 // EncodeVideoFrame(), the encoder will process this request asynchronously.
72 virtual void EmitFrames();
78 #endif // MEDIA_CAST_SENDER_VIDEO_ENCODER_H_