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

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

Issue 2048033003: Refactoring: CastTransport InitializeAudio/InitializeVideo. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add comments. Created 4 years, 5 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/audio_sender.h" 5 #include "media/cast/sender/audio_sender.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/memory/ptr_util.h"
12 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
13 #include "media/cast/common/rtp_time.h" 12 #include "media/cast/common/rtp_time.h"
14 #include "media/cast/net/cast_transport_config.h" 13 #include "media/cast/net/cast_transport_config.h"
15 #include "media/cast/sender/audio_encoder.h" 14 #include "media/cast/sender/audio_encoder.h"
16 15
17 namespace media { 16 namespace media {
18 namespace cast { 17 namespace cast {
19 18
20 AudioSender::AudioSender(scoped_refptr<CastEnvironment> cast_environment, 19 AudioSender::AudioSender(scoped_refptr<CastEnvironment> cast_environment,
21 const FrameSenderConfig& audio_config, 20 const FrameSenderConfig& audio_config,
22 const StatusChangeCallback& status_change_cb, 21 const StatusChangeCallback& status_change_cb,
23 CastTransport* const transport_sender) 22 CastTransport* const transport_sender)
24 : FrameSender(cast_environment, 23 : FrameSender(cast_environment,
25 true,
26 transport_sender, 24 transport_sender,
27 audio_config.rtp_timebase, 25 audio_config,
28 audio_config.sender_ssrc,
29 0, // |max_frame_rate_| is set after encoder initialization.
30 audio_config.min_playout_delay,
31 audio_config.max_playout_delay,
32 audio_config.animated_playout_delay,
33 NewFixedCongestionControl(audio_config.max_bitrate)), 26 NewFixedCongestionControl(audio_config.max_bitrate)),
34 samples_in_encoder_(0), 27 samples_in_encoder_(0),
35 weak_factory_(this) { 28 weak_factory_(this) {
36 if (!audio_config.use_external_encoder) { 29 if (!audio_config.use_external_encoder) {
37 audio_encoder_.reset(new AudioEncoder( 30 audio_encoder_.reset(new AudioEncoder(
38 cast_environment, audio_config.channels, audio_config.rtp_timebase, 31 cast_environment, audio_config.channels, audio_config.rtp_timebase,
39 audio_config.max_bitrate, audio_config.codec, 32 audio_config.max_bitrate, audio_config.codec,
40 base::Bind(&AudioSender::OnEncodedAudioFrame, 33 base::Bind(&AudioSender::OnEncodedAudioFrame,
41 weak_factory_.GetWeakPtr(), audio_config.max_bitrate))); 34 weak_factory_.GetWeakPtr(), audio_config.max_bitrate)));
42 } 35 }
43 36
44 // AudioEncoder provides no operational status changes during normal use. 37 // AudioEncoder provides no operational status changes during normal use.
45 // Post a task now with its initialization result status to allow the client 38 // Post a task now with its initialization result status to allow the client
46 // to start sending frames. 39 // to start sending frames.
47 cast_environment_->PostTask( 40 cast_environment_->PostTask(
48 CastEnvironment::MAIN, 41 CastEnvironment::MAIN,
49 FROM_HERE, 42 FROM_HERE,
50 base::Bind(status_change_cb, 43 base::Bind(status_change_cb,
51 audio_encoder_ ? audio_encoder_->InitializationResult() : 44 audio_encoder_ ? audio_encoder_->InitializationResult() :
52 STATUS_INVALID_CONFIGURATION)); 45 STATUS_INVALID_CONFIGURATION));
53 46
54 // The number of samples per encoded audio frame depends on the codec and its 47 // The number of samples per encoded audio frame depends on the codec and its
55 // initialization parameters. Now that we have an encoder, we can calculate 48 // initialization parameters. Now that we have an encoder, we can calculate
56 // the maximum frame rate. 49 // the maximum frame rate.
57 max_frame_rate_ = 50 max_frame_rate_ =
58 audio_config.rtp_timebase / audio_encoder_->GetSamplesPerFrame(); 51 audio_config.rtp_timebase / audio_encoder_->GetSamplesPerFrame();
59
60 media::cast::CastTransportRtpConfig transport_config;
61 transport_config.ssrc = audio_config.sender_ssrc;
62 transport_config.feedback_ssrc = audio_config.receiver_ssrc;
63 transport_config.rtp_payload_type = audio_config.rtp_payload_type;
64 transport_config.aes_key = audio_config.aes_key;
65 transport_config.aes_iv_mask = audio_config.aes_iv_mask;
66
67 transport_sender->InitializeAudio(
68 transport_config, base::WrapUnique(new FrameSender::RtcpClient(
69 weak_factory_.GetWeakPtr())));
70 } 52 }
71 53
72 AudioSender::~AudioSender() {} 54 AudioSender::~AudioSender() {}
73 55
74 void AudioSender::InsertAudio(std::unique_ptr<AudioBus> audio_bus, 56 void AudioSender::InsertAudio(std::unique_ptr<AudioBus> audio_bus,
75 const base::TimeTicks& recorded_time) { 57 const base::TimeTicks& recorded_time) {
76 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); 58 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN));
77 59
78 if (!audio_encoder_) { 60 if (!audio_encoder_) {
79 NOTREACHED(); 61 NOTREACHED();
(...skipping 29 matching lines...) Expand all
109 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); 91 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN));
110 92
111 samples_in_encoder_ -= audio_encoder_->GetSamplesPerFrame() + samples_skipped; 93 samples_in_encoder_ -= audio_encoder_->GetSamplesPerFrame() + samples_skipped;
112 DCHECK_GE(samples_in_encoder_, 0); 94 DCHECK_GE(samples_in_encoder_, 0);
113 95
114 SendEncodedFrame(encoder_bitrate, std::move(encoded_frame)); 96 SendEncodedFrame(encoder_bitrate, std::move(encoded_frame));
115 } 97 }
116 98
117 } // namespace cast 99 } // namespace cast
118 } // namespace media 100 } // namespace media
OLDNEW
« no previous file with comments | « media/cast/net/rtp/rtp_packetizer_unittest.cc ('k') | media/cast/sender/audio_sender_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698