OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/audio_sender/audio_encoder.h" | 5 #include "media/cast/audio_sender/audio_encoder.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 CHECK_LE(samples_per_10ms_ * num_channels_, | 52 CHECK_LE(samples_per_10ms_ * num_channels_, |
53 EncodedAudioFrame::kMaxNumberOfSamples); | 53 EncodedAudioFrame::kMaxNumberOfSamples); |
54 } | 54 } |
55 | 55 |
56 virtual ~ImplBase() {} | 56 virtual ~ImplBase() {} |
57 | 57 |
58 void EncodeAudio(const AudioBus* audio_bus, | 58 void EncodeAudio(const AudioBus* audio_bus, |
59 const base::TimeTicks& recorded_time, | 59 const base::TimeTicks& recorded_time, |
60 const base::Closure& done_callback) { | 60 const base::Closure& done_callback) { |
61 int src_pos = 0; | 61 int src_pos = 0; |
62 while (src_pos < audio_bus->frames()) { | 62 while (audio_bus && src_pos < audio_bus->frames()) { |
63 const int num_samples_to_xfer = | 63 const int num_samples_to_xfer = |
64 std::min(samples_per_10ms_ - buffer_fill_end_, | 64 std::min(samples_per_10ms_ - buffer_fill_end_, |
65 audio_bus->frames() - src_pos); | 65 audio_bus->frames() - src_pos); |
66 DCHECK_EQ(audio_bus->channels(), num_channels_); | 66 DCHECK_EQ(audio_bus->channels(), num_channels_); |
67 TransferSamplesIntoBuffer( | 67 TransferSamplesIntoBuffer( |
68 audio_bus, src_pos, buffer_fill_end_, num_samples_to_xfer); | 68 audio_bus, src_pos, buffer_fill_end_, num_samples_to_xfer); |
69 src_pos += num_samples_to_xfer; | 69 src_pos += num_samples_to_xfer; |
70 buffer_fill_end_ += num_samples_to_xfer; | 70 buffer_fill_end_ += num_samples_to_xfer; |
71 | 71 |
72 if (src_pos == audio_bus->frames()) { | 72 if (src_pos == audio_bus->frames()) { |
73 cast_environment_->PostTask(CastEnvironment::MAIN, FROM_HERE, | 73 cast_environment_->PostTask(CastEnvironment::MAIN, FROM_HERE, |
74 done_callback); | 74 done_callback); |
75 // Note: |audio_bus| is now invalid.. | 75 // Note: |audio_bus| is invalid once done_callback is invoked. |
| 76 audio_bus = NULL; |
76 } | 77 } |
77 | 78 |
78 if (buffer_fill_end_ == samples_per_10ms_) { | 79 if (buffer_fill_end_ == samples_per_10ms_) { |
79 scoped_ptr<EncodedAudioFrame> audio_frame(new EncodedAudioFrame()); | 80 scoped_ptr<EncodedAudioFrame> audio_frame(new EncodedAudioFrame()); |
80 audio_frame->codec = codec_; | 81 audio_frame->codec = codec_; |
81 audio_frame->frame_id = frame_id_++; | 82 audio_frame->frame_id = frame_id_++; |
82 audio_frame->samples = samples_per_10ms_; | 83 audio_frame->samples = samples_per_10ms_; |
83 if (EncodeFromFilledBuffer(&audio_frame->data)) { | 84 if (EncodeFromFilledBuffer(&audio_frame->data)) { |
84 // Compute an offset to determine the recorded time for the first | 85 // Compute an offset to determine the recorded time for the first |
85 // audio sample in the buffer. | 86 // audio sample in the buffer. |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 const base::TimeTicks& recorded_time, | 286 const base::TimeTicks& recorded_time, |
286 const base::Closure& done_callback) { | 287 const base::Closure& done_callback) { |
287 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::AUDIO_ENCODER)); | 288 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::AUDIO_ENCODER)); |
288 impl_->EncodeAudio(audio_bus, recorded_time, done_callback); | 289 impl_->EncodeAudio(audio_bus, recorded_time, done_callback); |
289 cast_environment_->PostTask(CastEnvironment::MAIN, FROM_HERE, | 290 cast_environment_->PostTask(CastEnvironment::MAIN, FROM_HERE, |
290 base::Bind(LogAudioEncodedEvent, cast_environment_, recorded_time)); | 291 base::Bind(LogAudioEncodedEvent, cast_environment_, recorded_time)); |
291 } | 292 } |
292 | 293 |
293 } // namespace cast | 294 } // namespace cast |
294 } // namespace media | 295 } // namespace media |
OLD | NEW |