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

Side by Side Diff: media/cast/sender/video_encoder_impl.cc

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
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 #include "media/cast/sender/video_encoder_impl.h" 5 #include "media/cast/sender/video_encoder_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 encoder->Encode(video_frame, reference_time, encoded_frame.get()); 47 encoder->Encode(video_frame, reference_time, encoded_frame.get());
48 environment->PostTask( 48 environment->PostTask(
49 CastEnvironment::MAIN, 49 CastEnvironment::MAIN,
50 FROM_HERE, 50 FROM_HERE,
51 base::Bind(frame_encoded_callback, base::Passed(&encoded_frame))); 51 base::Bind(frame_encoded_callback, base::Passed(&encoded_frame)));
52 } 52 }
53 } // namespace 53 } // namespace
54 54
55 VideoEncoderImpl::VideoEncoderImpl( 55 VideoEncoderImpl::VideoEncoderImpl(
56 scoped_refptr<CastEnvironment> cast_environment, 56 scoped_refptr<CastEnvironment> cast_environment,
57 const VideoSenderConfig& video_config) 57 const VideoSenderConfig& video_config,
58 const CastInitializationCallback& initialization_cb)
58 : cast_environment_(cast_environment) { 59 : cast_environment_(cast_environment) {
59 CHECK(cast_environment_->HasVideoThread()); 60 CHECK(cast_environment_->HasVideoThread());
60 if (video_config.codec == CODEC_VIDEO_VP8) { 61 if (video_config.codec == CODEC_VIDEO_VP8) {
61 encoder_.reset(new Vp8Encoder(video_config)); 62 encoder_.reset(new Vp8Encoder(video_config));
62 cast_environment_->PostTask(CastEnvironment::VIDEO, 63 cast_environment_->PostTask(CastEnvironment::VIDEO,
63 FROM_HERE, 64 FROM_HERE,
64 base::Bind(&InitializeEncoderOnEncoderThread, 65 base::Bind(&InitializeEncoderOnEncoderThread,
65 cast_environment, 66 cast_environment,
66 encoder_.get())); 67 encoder_.get()));
67 #ifndef OFFICIAL_BUILD 68 #ifndef OFFICIAL_BUILD
68 } else if (video_config.codec == CODEC_VIDEO_FAKE) { 69 } else if (video_config.codec == CODEC_VIDEO_FAKE) {
69 encoder_.reset(new FakeSoftwareVideoEncoder(video_config)); 70 encoder_.reset(new FakeSoftwareVideoEncoder(video_config));
70 #endif 71 #endif
71 } else { 72 } else {
72 DCHECK(false) << "Invalid config"; // Codec not supported. 73 DCHECK(false) << "Invalid config"; // Codec not supported.
73 } 74 }
74 75
75 dynamic_config_.key_frame_requested = false; 76 dynamic_config_.key_frame_requested = false;
76 dynamic_config_.latest_frame_id_to_reference = kStartFrameId; 77 dynamic_config_.latest_frame_id_to_reference = kStartFrameId;
77 dynamic_config_.bit_rate = video_config.start_bitrate; 78 dynamic_config_.bit_rate = video_config.start_bitrate;
79
80 if (!initialization_cb.is_null()) {
81 cast_environment_->PostTask(
82 CastEnvironment::MAIN,
83 FROM_HERE,
84 base::Bind(initialization_cb,
85 encoder_.get() ? STATUS_VIDEO_INITIALIZED :
86 STATUS_UNSUPPORTED_VIDEO_CODEC));
87 }
78 } 88 }
79 89
80 VideoEncoderImpl::~VideoEncoderImpl() { 90 VideoEncoderImpl::~VideoEncoderImpl() {
81 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); 91 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN));
82 if (encoder_) { 92 if (encoder_) {
83 cast_environment_->PostTask( 93 cast_environment_->PostTask(
84 CastEnvironment::VIDEO, 94 CastEnvironment::VIDEO,
85 FROM_HERE, 95 FROM_HERE,
86 base::Bind(&base::DeletePointer<SoftwareVideoEncoder>, 96 base::Bind(&base::DeletePointer<SoftwareVideoEncoder>,
87 encoder_.release())); 97 encoder_.release()));
88 } 98 }
89 } 99 }
90 100
101 bool VideoEncoderImpl::CanEncodeVariedFrameSizes() const {
102 // Both the VP8Encoder and FakeSoftwareVideoEncoder support calls to
103 // EncodeVideoFrame() with different frame sizes.
104 return true;
105 }
106
91 bool VideoEncoderImpl::EncodeVideoFrame( 107 bool VideoEncoderImpl::EncodeVideoFrame(
92 const scoped_refptr<media::VideoFrame>& video_frame, 108 const scoped_refptr<media::VideoFrame>& video_frame,
93 const base::TimeTicks& reference_time, 109 const base::TimeTicks& reference_time,
94 const FrameEncodedCallback& frame_encoded_callback) { 110 const FrameEncodedCallback& frame_encoded_callback) {
95 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); 111 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN));
112 DCHECK(!video_frame->visible_rect().IsEmpty());
113 DCHECK(!frame_encoded_callback.is_null());
114
96 cast_environment_->PostTask(CastEnvironment::VIDEO, 115 cast_environment_->PostTask(CastEnvironment::VIDEO,
97 FROM_HERE, 116 FROM_HERE,
98 base::Bind(&EncodeVideoFrameOnEncoderThread, 117 base::Bind(&EncodeVideoFrameOnEncoderThread,
99 cast_environment_, 118 cast_environment_,
100 encoder_.get(), 119 encoder_.get(),
101 video_frame, 120 video_frame,
102 reference_time, 121 reference_time,
103 dynamic_config_, 122 dynamic_config_,
104 frame_encoded_callback)); 123 frame_encoded_callback));
105 124
(...skipping 11 matching lines...) Expand all
117 dynamic_config_.key_frame_requested = true; 136 dynamic_config_.key_frame_requested = true;
118 } 137 }
119 138
120 // Inform the encoder to only reference frames older or equal to frame_id; 139 // Inform the encoder to only reference frames older or equal to frame_id;
121 void VideoEncoderImpl::LatestFrameIdToReference(uint32 frame_id) { 140 void VideoEncoderImpl::LatestFrameIdToReference(uint32 frame_id) {
122 dynamic_config_.latest_frame_id_to_reference = frame_id; 141 dynamic_config_.latest_frame_id_to_reference = frame_id;
123 } 142 }
124 143
125 } // namespace cast 144 } // namespace cast
126 } // namespace media 145 } // namespace media
OLDNEW
« no previous file with comments | « media/cast/sender/video_encoder_impl.h ('k') | media/cast/sender/video_encoder_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698