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

Side by Side Diff: media/cast/video_sender/video_encoder.h

Issue 116623002: Cast: Adding support for GPU accelerated encode (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed merge nits Created 6 years, 11 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef MEDIA_CAST_VIDEO_SENDER_VIDEO_ENCODER_H_ 5 #ifndef MEDIA_CAST_VIDEO_SENDER_VIDEO_ENCODER_H_
6 #define MEDIA_CAST_VIDEO_SENDER_VIDEO_ENCODER_H_ 6 #define MEDIA_CAST_VIDEO_SENDER_VIDEO_ENCODER_H_
7 7
8 #include "base/callback.h"
9 #include "base/memory/ref_counted.h"
8 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
9 #include "base/memory/weak_ptr.h" 11 #include "base/memory/weak_ptr.h"
10 #include "base/message_loop/message_loop.h" 12 #include "base/time/time.h"
13 #include "media/base/video_frame.h"
11 #include "media/cast/cast_config.h" 14 #include "media/cast/cast_config.h"
12 #include "media/cast/cast_environment.h" 15 #include "media/cast/cast_environment.h"
13 #include "media/cast/video_sender/codecs/vp8/vp8_encoder.h"
14
15 namespace media {
16 class VideoFrame;
17 }
18 16
19 namespace media { 17 namespace media {
20 namespace cast { 18 namespace cast {
21 19
22 // This object is called external from the main cast thread and internally from 20 // All these functions are called from the main cast thread.
23 // the video encoder thread. 21 class VideoEncoder {
24 class VideoEncoder : public VideoEncoderController {
25 public: 22 public:
26 typedef base::Callback<void(scoped_ptr<EncodedVideoFrame>, 23 typedef base::Callback<void(scoped_ptr<EncodedVideoFrame>,
27 const base::TimeTicks&)> FrameEncodedCallback; 24 const base::TimeTicks&)> FrameEncodedCallback;
28 25
29 VideoEncoder(scoped_refptr<CastEnvironment> cast_environment, 26 virtual ~VideoEncoder() {}
30 const VideoSenderConfig& video_config,
31 uint8 max_unacked_frames);
32 27
33 virtual ~VideoEncoder();
34
35 // Called from the main cast thread. This function post the encode task to the
36 // video encoder thread;
37 // The video_frame must be valid until the closure callback is called. 28 // The video_frame must be valid until the closure callback is called.
38 // The closure callback is called from the video encoder thread as soon as 29 // The closure callback is called from the video encoder thread as soon as
39 // the encoder is done with the frame; it does not mean that the encoded frame 30 // the encoder is done with the frame; it does not mean that the encoded frame
40 // has been sent out. 31 // has been sent out.
41 // Once the encoded frame is ready the frame_encoded_callback is called. 32 // Once the encoded frame is ready the frame_encoded_callback is called.
42 bool EncodeVideoFrame(const scoped_refptr<media::VideoFrame>& video_frame, 33 virtual bool EncodeVideoFrame(
43 const base::TimeTicks& capture_time,
44 const FrameEncodedCallback& frame_encoded_callback);
45
46 protected:
47 struct CodecDynamicConfig {
48 bool key_frame_requested;
49 uint32 latest_frame_id_to_reference;
50 int bit_rate;
51 };
52
53 // The actual encode, called from the video encoder thread.
54 void EncodeVideoFrameEncoderThread(
55 const scoped_refptr<media::VideoFrame>& video_frame, 34 const scoped_refptr<media::VideoFrame>& video_frame,
56 const base::TimeTicks& capture_time, 35 const base::TimeTicks& capture_time,
57 const CodecDynamicConfig& dynamic_config, 36 const FrameEncodedCallback& frame_encoded_callback) = 0;
58 const FrameEncodedCallback& frame_encoded_callback);
59 37
60 // The following functions are called from the main cast thread. 38 // Inform the encoder about the new target bit rate.
61 virtual void SetBitRate(int new_bit_rate) OVERRIDE; 39 virtual void SetBitRate(int new_bit_rate) = 0;
62 virtual void SkipNextFrame(bool skip_next_frame) OVERRIDE;
63 virtual void GenerateKeyFrame() OVERRIDE;
64 virtual void LatestFrameIdToReference(uint32 frame_id) OVERRIDE;
65 virtual int NumberOfSkippedFrames() const OVERRIDE;
66 40
67 private: 41 // Inform the encoder to not encode the next frame.
68 friend class base::RefCountedThreadSafe<VideoEncoder>; 42 // Note: this setting is sticky and should last until called with false.
43 virtual void SkipNextFrame(bool skip_next_frame) = 0;
69 44
70 const VideoSenderConfig video_config_; 45 // Inform the encoder to encode the next frame as a key frame.
71 scoped_refptr<CastEnvironment> cast_environment_; 46 virtual void GenerateKeyFrame() = 0;
72 scoped_ptr<Vp8Encoder> vp8_encoder_;
73 CodecDynamicConfig dynamic_config_;
74 bool skip_next_frame_;
75 int skip_count_;
76 47
77 DISALLOW_COPY_AND_ASSIGN(VideoEncoder); 48 // Inform the encoder to only reference frames older or equal to frame_id;
49 virtual void LatestFrameIdToReference(uint32 frame_id) = 0;
50
51 // Query the codec about how many frames it has skipped due to slow ACK.
52 virtual int NumberOfSkippedFrames() const = 0;
78 }; 53 };
79 54
80 } // namespace cast 55 } // namespace cast
81 } // namespace media 56 } // namespace media
82 57
83 #endif // MEDIA_CAST_VIDEO_SENDER_VIDEO_ENCODER_H_ 58 #endif // MEDIA_CAST_VIDEO_SENDER_VIDEO_ENCODER_H_
59
OLDNEW
« no previous file with comments | « media/cast/video_sender/mock_video_encoder_controller.cc ('k') | media/cast/video_sender/video_encoder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698