OLD | NEW |
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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 const StatusChangeCallback& status_change_cb) |
59 : cast_environment_(cast_environment) { | 59 : cast_environment_(cast_environment) { |
60 CHECK(cast_environment_->HasVideoThread()); | 60 CHECK(cast_environment_->HasVideoThread()); |
| 61 DCHECK(!status_change_cb.is_null()); |
| 62 |
61 if (video_config.codec == CODEC_VIDEO_VP8) { | 63 if (video_config.codec == CODEC_VIDEO_VP8) { |
62 encoder_.reset(new Vp8Encoder(video_config)); | 64 encoder_.reset(new Vp8Encoder(video_config)); |
63 cast_environment_->PostTask(CastEnvironment::VIDEO, | 65 cast_environment_->PostTask(CastEnvironment::VIDEO, |
64 FROM_HERE, | 66 FROM_HERE, |
65 base::Bind(&InitializeEncoderOnEncoderThread, | 67 base::Bind(&InitializeEncoderOnEncoderThread, |
66 cast_environment, | 68 cast_environment, |
67 encoder_.get())); | 69 encoder_.get())); |
68 #ifndef OFFICIAL_BUILD | 70 #ifndef OFFICIAL_BUILD |
69 } else if (video_config.codec == CODEC_VIDEO_FAKE) { | 71 } else if (video_config.codec == CODEC_VIDEO_FAKE) { |
70 encoder_.reset(new FakeSoftwareVideoEncoder(video_config)); | 72 encoder_.reset(new FakeSoftwareVideoEncoder(video_config)); |
71 #endif | 73 #endif |
72 } else { | 74 } else { |
73 DCHECK(false) << "Invalid config"; // Codec not supported. | 75 DCHECK(false) << "Invalid config"; // Codec not supported. |
74 } | 76 } |
75 | 77 |
76 dynamic_config_.key_frame_requested = false; | 78 dynamic_config_.key_frame_requested = false; |
77 dynamic_config_.latest_frame_id_to_reference = kStartFrameId; | 79 dynamic_config_.latest_frame_id_to_reference = kStartFrameId; |
78 dynamic_config_.bit_rate = video_config.start_bitrate; | 80 dynamic_config_.bit_rate = video_config.start_bitrate; |
79 | 81 |
80 if (!initialization_cb.is_null()) { | 82 cast_environment_->PostTask( |
81 cast_environment_->PostTask( | 83 CastEnvironment::MAIN, |
82 CastEnvironment::MAIN, | 84 FROM_HERE, |
83 FROM_HERE, | 85 base::Bind(status_change_cb, |
84 base::Bind(initialization_cb, | 86 encoder_.get() ? STATUS_INITIALIZED : |
85 encoder_.get() ? STATUS_VIDEO_INITIALIZED : | 87 STATUS_UNSUPPORTED_CODEC)); |
86 STATUS_UNSUPPORTED_VIDEO_CODEC)); | |
87 } | |
88 } | 88 } |
89 | 89 |
90 VideoEncoderImpl::~VideoEncoderImpl() { | 90 VideoEncoderImpl::~VideoEncoderImpl() { |
91 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | 91 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
92 if (encoder_) { | 92 if (encoder_) { |
93 cast_environment_->PostTask( | 93 cast_environment_->PostTask( |
94 CastEnvironment::VIDEO, | 94 CastEnvironment::VIDEO, |
95 FROM_HERE, | 95 FROM_HERE, |
96 base::Bind(&base::DeletePointer<SoftwareVideoEncoder>, | 96 base::Bind(&base::DeletePointer<SoftwareVideoEncoder>, |
97 encoder_.release())); | 97 encoder_.release())); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 dynamic_config_.key_frame_requested = true; | 136 dynamic_config_.key_frame_requested = true; |
137 } | 137 } |
138 | 138 |
139 // 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; |
140 void VideoEncoderImpl::LatestFrameIdToReference(uint32 frame_id) { | 140 void VideoEncoderImpl::LatestFrameIdToReference(uint32 frame_id) { |
141 dynamic_config_.latest_frame_id_to_reference = frame_id; | 141 dynamic_config_.latest_frame_id_to_reference = frame_id; |
142 } | 142 } |
143 | 143 |
144 } // namespace cast | 144 } // namespace cast |
145 } // namespace media | 145 } // namespace media |
OLD | NEW |