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

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

Issue 892383002: RELAND: [Cast] Software encoder support for varying video frame sizes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix for 'access to uninitialized memory' error. 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/sender/video_sender.cc ('k') | media/cast/sender/vp8_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_CODECS_VP8_VP8_ENCODER_H_ 5 #ifndef MEDIA_CAST_SENDER_CODECS_VP8_VP8_ENCODER_H_
6 #define MEDIA_CAST_SENDER_CODECS_VP8_VP8_ENCODER_H_ 6 #define MEDIA_CAST_SENDER_CODECS_VP8_VP8_ENCODER_H_
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/threading/thread_checker.h" 10 #include "base/threading/thread_checker.h"
11 #include "media/cast/cast_config.h" 11 #include "media/cast/cast_config.h"
12 #include "media/cast/sender/software_video_encoder.h" 12 #include "media/cast/sender/software_video_encoder.h"
13 #include "third_party/libvpx/source/libvpx/vpx/vpx_encoder.h" 13 #include "third_party/libvpx/source/libvpx/vpx/vpx_encoder.h"
14 #include "ui/gfx/geometry/size.h"
14 15
15 namespace media { 16 namespace media {
16 class VideoFrame; 17 class VideoFrame;
17 } 18 }
18 19
19 namespace media { 20 namespace media {
20 namespace cast { 21 namespace cast {
21 22
22 class Vp8Encoder : public SoftwareVideoEncoder { 23 class Vp8Encoder : public SoftwareVideoEncoder {
23 public: 24 public:
(...skipping 25 matching lines...) Expand all
49 kBufferSent, 50 kBufferSent,
50 kBufferAcked 51 kBufferAcked
51 }; 52 };
52 53
53 struct BufferState { 54 struct BufferState {
54 uint32 frame_id; 55 uint32 frame_id;
55 Vp8BufferState state; 56 Vp8BufferState state;
56 }; 57 };
57 58
58 bool is_initialized() const { 59 bool is_initialized() const {
59 // Initialize() sets the timebase denominator value to non-zero if the 60 // ConfigureForNewFrameSize() sets the timebase denominator value to
60 // encoder is successfully initialized, and it is zero otherwise. 61 // non-zero if the encoder is successfully initialized, and it is zero
62 // otherwise.
61 return config_.g_timebase.den != 0; 63 return config_.g_timebase.den != 0;
62 } 64 }
63 65
66 // If the |encoder_| is live, attempt reconfiguration to allow it to encode
67 // frames at a new |frame_size|. Otherwise, tear it down and re-create a new
68 // |encoder_| instance.
69 void ConfigureForNewFrameSize(const gfx::Size& frame_size);
70
64 // Calculate which next Vp8 buffers to update with the next frame. 71 // Calculate which next Vp8 buffers to update with the next frame.
65 Vp8Buffers GetNextBufferToUpdate(); 72 Vp8Buffers GetNextBufferToUpdate();
66 73
67 // Get encoder flags for our referenced encoder buffers. 74 // Get encoder flags for our referenced encoder buffers.
68 // Return which previous frame to reference. 75 // Return which previous frame to reference.
69 uint32 GetCodecReferenceFlags(vpx_codec_flags_t* flags); 76 uint32 GetCodecReferenceFlags(vpx_codec_flags_t* flags);
70 77
71 // Get encoder flags for our encoder buffers to update with next frame. 78 // Get encoder flags for our encoder buffers to update with next frame.
72 void GetCodecUpdateFlags(Vp8Buffers buffer_to_update, 79 void GetCodecUpdateFlags(Vp8Buffers buffer_to_update,
73 vpx_codec_flags_t* flags); 80 vpx_codec_flags_t* flags);
74 81
75 const VideoSenderConfig cast_config_; 82 const VideoSenderConfig cast_config_;
76 const bool use_multiple_video_buffers_; 83 const bool use_multiple_video_buffers_;
77 84
78 // VP8 internal objects. These are valid for use only while is_initialized() 85 // VP8 internal objects. These are valid for use only while is_initialized()
79 // returns true. 86 // returns true.
80 vpx_codec_enc_cfg_t config_; 87 vpx_codec_enc_cfg_t config_;
81 vpx_codec_ctx_t encoder_; 88 vpx_codec_ctx_t encoder_;
82 89
83 // Wrapper for access to YUV data planes in a media::VideoFrame.
84 vpx_image_t* raw_image_;
85
86 // Set to true to request the next frame emitted by Vp8Encoder be a key frame. 90 // Set to true to request the next frame emitted by Vp8Encoder be a key frame.
87 bool key_frame_requested_; 91 bool key_frame_requested_;
88 92
93 // Saves the current bitrate setting, for when the |encoder_| is reconfigured
94 // for different frame sizes.
95 int bitrate_kbit_;
96
89 // The |VideoFrame::timestamp()| of the last encoded frame. This is used to 97 // The |VideoFrame::timestamp()| of the last encoded frame. This is used to
90 // predict the duration of the next frame. 98 // predict the duration of the next frame.
91 base::TimeDelta last_frame_timestamp_; 99 base::TimeDelta last_frame_timestamp_;
92 100
93 // The last encoded frame's ID. 101 // The last encoded frame's ID.
94 uint32 last_encoded_frame_id_; 102 uint32 last_encoded_frame_id_;
95 103
96 // Used to track which buffers are old enough to be re-used. 104 // Used to track which buffers are old enough to be re-used.
97 uint32 last_acked_frame_id_; 105 uint32 last_acked_frame_id_;
98 106
99 // Used by GetNextBufferToUpdate() to track how many consecutive times the 107 // Used by GetNextBufferToUpdate() to track how many consecutive times the
100 // newest buffer had to be overwritten. 108 // newest buffer had to be overwritten.
101 int undroppable_frames_; 109 int undroppable_frames_;
102 110
103 // Tracks the lifecycle and dependency state of each of the three buffers. 111 // Tracks the lifecycle and dependency state of each of the three buffers.
104 BufferState buffer_state_[kNumberOfVp8VideoBuffers]; 112 BufferState buffer_state_[kNumberOfVp8VideoBuffers];
105 113
106 // This is bound to the thread where Initialize() is called. 114 // This is bound to the thread where Initialize() is called.
107 base::ThreadChecker thread_checker_; 115 base::ThreadChecker thread_checker_;
108 116
109 DISALLOW_COPY_AND_ASSIGN(Vp8Encoder); 117 DISALLOW_COPY_AND_ASSIGN(Vp8Encoder);
110 }; 118 };
111 119
112 } // namespace cast 120 } // namespace cast
113 } // namespace media 121 } // namespace media
114 122
115 #endif // MEDIA_CAST_SENDER_CODECS_VP8_VP8_ENCODER_H_ 123 #endif // MEDIA_CAST_SENDER_CODECS_VP8_VP8_ENCODER_H_
OLDNEW
« no previous file with comments | « media/cast/sender/video_sender.cc ('k') | media/cast/sender/vp8_encoder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698