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

Side by Side Diff: media/cast/sender/external_video_encoder.h

Issue 868803007: [Cast] Refactor ExternalVideoEncoder for cleaner/simpler encapsulation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add clarification comments and TODOs. Created 5 years, 10 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
« no previous file with comments | « media/cast/cast_testing.gypi ('k') | media/cast/sender/external_video_encoder.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 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_SENDER_EXTERNAL_VIDEO_ENCODER_H_ 5 #ifndef MEDIA_CAST_SENDER_EXTERNAL_VIDEO_ENCODER_H_
6 #define MEDIA_CAST_SENDER_EXTERNAL_VIDEO_ENCODER_H_ 6 #define MEDIA_CAST_SENDER_EXTERNAL_VIDEO_ENCODER_H_
7 7
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/memory/weak_ptr.h" 9 #include "base/memory/weak_ptr.h"
10 #include "media/cast/cast_config.h" 10 #include "media/cast/cast_config.h"
11 #include "media/cast/cast_environment.h" 11 #include "media/cast/cast_environment.h"
12 #include "media/cast/sender/video_encoder.h" 12 #include "media/cast/sender/video_encoder.h"
13 #include "media/video/video_encode_accelerator.h" 13 #include "media/video/video_encode_accelerator.h"
14 14 #include "ui/gfx/geometry/size.h"
15 namespace media {
16 class VideoFrame;
17 }
18 15
19 namespace media { 16 namespace media {
20 namespace cast { 17 namespace cast {
21 18
22 class LocalVideoEncodeAcceleratorClient; 19 // Cast MAIN thread proxy to the internal media::VideoEncodeAccelerator
23 20 // implementation running on a separate thread. Encodes media::VideoFrames and
24 // This object is called external from the main cast thread and internally from 21 // emits media::cast::EncodedFrames.
25 // the video encoder thread.
26 class ExternalVideoEncoder : public VideoEncoder { 22 class ExternalVideoEncoder : public VideoEncoder {
27 public: 23 public:
28 ExternalVideoEncoder( 24 ExternalVideoEncoder(
29 scoped_refptr<CastEnvironment> cast_environment, 25 const scoped_refptr<CastEnvironment>& cast_environment,
30 const VideoSenderConfig& video_config, 26 const VideoSenderConfig& video_config,
27 const gfx::Size& frame_size,
31 const CastInitializationCallback& initialization_cb, 28 const CastInitializationCallback& initialization_cb,
32 const CreateVideoEncodeAcceleratorCallback& create_vea_cb, 29 const CreateVideoEncodeAcceleratorCallback& create_vea_cb,
33 const CreateVideoEncodeMemoryCallback& create_video_encode_mem_cb); 30 const CreateVideoEncodeMemoryCallback& create_video_encode_memory_cb);
34 31
35 ~ExternalVideoEncoder() override; 32 ~ExternalVideoEncoder() override;
36 33
37 // VideoEncoder implementation. 34 // VideoEncoder implementation.
38 bool EncodeVideoFrame( 35 bool EncodeVideoFrame(
39 const scoped_refptr<media::VideoFrame>& video_frame, 36 const scoped_refptr<media::VideoFrame>& video_frame,
40 const base::TimeTicks& reference_time, 37 const base::TimeTicks& reference_time,
41 const FrameEncodedCallback& frame_encoded_callback) override; 38 const FrameEncodedCallback& frame_encoded_callback) override;
42 void SetBitRate(int new_bit_rate) override; 39 void SetBitRate(int new_bit_rate) override;
43 void GenerateKeyFrame() override; 40 void GenerateKeyFrame() override;
44 void LatestFrameIdToReference(uint32 frame_id) override; 41 void LatestFrameIdToReference(uint32 frame_id) override;
45 42
46 // Called when video_accelerator_client_ has finished creating the VEA and 43 private:
47 // is ready for use. 44 class VEAClientImpl;
45
46 // Method invoked by the CreateVideoEncodeAcceleratorCallback to construct a
47 // VEAClientImpl to own and interface with a new |vea|. Upon return,
48 // |client_| holds a reference to the new VEAClientImpl.
48 void OnCreateVideoEncodeAccelerator( 49 void OnCreateVideoEncodeAccelerator(
49 scoped_refptr<base::SingleThreadTaskRunner> encoder_task_runner); 50 const gfx::Size& frame_size,
51 VideoCodecProfile codec_profile,
52 int max_frame_rate,
53 const CastInitializationCallback& initialization_cb,
54 scoped_refptr<base::SingleThreadTaskRunner> encoder_task_runner,
55 scoped_ptr<media::VideoEncodeAccelerator> vea);
50 56
51 protected: 57 const scoped_refptr<CastEnvironment> cast_environment_;
52 // If |success| is true then encoder is initialized successfully. 58 const CreateVideoEncodeMemoryCallback create_video_encode_memory_cb_;
53 // Otherwise encoder initialization failed. 59 int bit_rate_;
54 void EncoderInitialized(bool success);
55 void EncoderError();
56
57 private:
58 friend class LocalVideoEncodeAcceleratorClient;
59
60 VideoSenderConfig video_config_;
61 scoped_refptr<CastEnvironment> cast_environment_;
62
63 bool encoder_active_;
64 bool key_frame_requested_; 60 bool key_frame_requested_;
65 61
66 scoped_refptr<LocalVideoEncodeAcceleratorClient> video_accelerator_client_; 62 scoped_refptr<VEAClientImpl> client_;
67 scoped_refptr<base::SingleThreadTaskRunner> encoder_task_runner_;
68 63
69 CastInitializationCallback initialization_cb_; 64 // Provides a weak pointer for the OnCreateVideoEncoderAccelerator() callback.
70
71 // Weak pointer factory for posting back LocalVideoEncodeAcceleratorClient
72 // notifications to ExternalVideoEncoder.
73 // NOTE: Weak pointers must be invalidated before all other member variables. 65 // NOTE: Weak pointers must be invalidated before all other member variables.
74 base::WeakPtrFactory<ExternalVideoEncoder> weak_factory_; 66 base::WeakPtrFactory<ExternalVideoEncoder> weak_factory_;
75 67
76 DISALLOW_COPY_AND_ASSIGN(ExternalVideoEncoder); 68 DISALLOW_COPY_AND_ASSIGN(ExternalVideoEncoder);
77 }; 69 };
78 70
79 } // namespace cast 71 } // namespace cast
80 } // namespace media 72 } // namespace media
81 73
82 #endif // MEDIA_CAST_SENDER_EXTERNAL_VIDEO_ENCODER_H_ 74 #endif // MEDIA_CAST_SENDER_EXTERNAL_VIDEO_ENCODER_H_
OLDNEW
« no previous file with comments | « media/cast/cast_testing.gypi ('k') | media/cast/sender/external_video_encoder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698