| 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/audio_encoder.h" | 5 #include "media/cast/sender/audio_encoder.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <limits> | 10 #include <limits> |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 TRACE_EVENT_SCOPE_THREAD, | 117 TRACE_EVENT_SCOPE_THREAD, |
| 118 "frames missed", num_frames_missed, | 118 "frames missed", num_frames_missed, |
| 119 "samples dropped", samples_dropped_from_buffer_); | 119 "samples dropped", samples_dropped_from_buffer_); |
| 120 } | 120 } |
| 121 } | 121 } |
| 122 frame_capture_time_ = recorded_time - buffer_fill_duration; | 122 frame_capture_time_ = recorded_time - buffer_fill_duration; |
| 123 | 123 |
| 124 // Encode all audio in |audio_bus| into zero or more frames. | 124 // Encode all audio in |audio_bus| into zero or more frames. |
| 125 int src_pos = 0; | 125 int src_pos = 0; |
| 126 while (src_pos < audio_bus->frames()) { | 126 while (src_pos < audio_bus->frames()) { |
| 127 // Note: This is used to compute the deadline utilization and so it uses | 127 // Note: This is used to compute the encoder utilization and so it uses |
| 128 // the real-world clock instead of the CastEnvironment clock, the latter | 128 // the real-world clock instead of the CastEnvironment clock, the latter |
| 129 // of which might be simulated. | 129 // of which might be simulated. |
| 130 const base::TimeTicks start_time = base::TimeTicks::Now(); | 130 const base::TimeTicks start_time = base::TimeTicks::Now(); |
| 131 | 131 |
| 132 const int num_samples_to_xfer = std::min( | 132 const int num_samples_to_xfer = std::min( |
| 133 samples_per_frame_ - buffer_fill_end_, audio_bus->frames() - src_pos); | 133 samples_per_frame_ - buffer_fill_end_, audio_bus->frames() - src_pos); |
| 134 DCHECK_EQ(audio_bus->channels(), num_channels_); | 134 DCHECK_EQ(audio_bus->channels(), num_channels_); |
| 135 TransferSamplesIntoBuffer( | 135 TransferSamplesIntoBuffer( |
| 136 audio_bus.get(), src_pos, buffer_fill_end_, num_samples_to_xfer); | 136 audio_bus.get(), src_pos, buffer_fill_end_, num_samples_to_xfer); |
| 137 src_pos += num_samples_to_xfer; | 137 src_pos += num_samples_to_xfer; |
| 138 buffer_fill_end_ += num_samples_to_xfer; | 138 buffer_fill_end_ += num_samples_to_xfer; |
| 139 | 139 |
| 140 if (buffer_fill_end_ < samples_per_frame_) | 140 if (buffer_fill_end_ < samples_per_frame_) |
| 141 break; | 141 break; |
| 142 | 142 |
| 143 std::unique_ptr<SenderEncodedFrame> audio_frame(new SenderEncodedFrame()); | 143 std::unique_ptr<SenderEncodedFrame> audio_frame(new SenderEncodedFrame()); |
| 144 audio_frame->dependency = EncodedFrame::KEY; | 144 audio_frame->dependency = EncodedFrame::KEY; |
| 145 audio_frame->frame_id = frame_id_; | 145 audio_frame->frame_id = frame_id_; |
| 146 audio_frame->referenced_frame_id = frame_id_; | 146 audio_frame->referenced_frame_id = frame_id_; |
| 147 audio_frame->rtp_timestamp = frame_rtp_timestamp_; | 147 audio_frame->rtp_timestamp = frame_rtp_timestamp_; |
| 148 audio_frame->reference_time = frame_capture_time_; | 148 audio_frame->reference_time = frame_capture_time_; |
| 149 | 149 |
| 150 TRACE_EVENT_ASYNC_BEGIN2("cast.stream", "Audio Encode", audio_frame.get(), | 150 TRACE_EVENT_ASYNC_BEGIN2("cast.stream", "Audio Encode", audio_frame.get(), |
| 151 "frame_id", frame_id_.lower_32_bits(), | 151 "frame_id", frame_id_.lower_32_bits(), |
| 152 "rtp_timestamp", | 152 "rtp_timestamp", |
| 153 frame_rtp_timestamp_.lower_32_bits()); | 153 frame_rtp_timestamp_.lower_32_bits()); |
| 154 if (EncodeFromFilledBuffer(&audio_frame->data)) { | 154 if (EncodeFromFilledBuffer(&audio_frame->data)) { |
| 155 // Compute deadline utilization as the real-world time elapsed divided | 155 // Compute encoder utilization as the real-world time elapsed divided |
| 156 // by the signal duration. | 156 // by the signal duration. |
| 157 audio_frame->deadline_utilization = | 157 audio_frame->encoder_utilization = |
| 158 (base::TimeTicks::Now() - start_time).InSecondsF() / | 158 (base::TimeTicks::Now() - start_time).InSecondsF() / |
| 159 frame_duration_.InSecondsF(); | 159 frame_duration_.InSecondsF(); |
| 160 | 160 |
| 161 TRACE_EVENT_ASYNC_END1("cast.stream", "Audio Encode", audio_frame.get(), | 161 TRACE_EVENT_ASYNC_END1("cast.stream", "Audio Encode", audio_frame.get(), |
| 162 "Deadline utilization", | 162 "encoder_utilization", |
| 163 audio_frame->deadline_utilization); | 163 audio_frame->encoder_utilization); |
| 164 | 164 |
| 165 audio_frame->encode_completion_time = | 165 audio_frame->encode_completion_time = |
| 166 cast_environment_->Clock()->NowTicks(); | 166 cast_environment_->Clock()->NowTicks(); |
| 167 cast_environment_->PostTask( | 167 cast_environment_->PostTask( |
| 168 CastEnvironment::MAIN, | 168 CastEnvironment::MAIN, |
| 169 FROM_HERE, | 169 FROM_HERE, |
| 170 base::Bind(callback_, | 170 base::Bind(callback_, |
| 171 base::Passed(&audio_frame), | 171 base::Passed(&audio_frame), |
| 172 samples_dropped_from_buffer_)); | 172 samples_dropped_from_buffer_)); |
| 173 samples_dropped_from_buffer_ = 0; | 173 samples_dropped_from_buffer_ = 0; |
| (...skipping 661 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 835 cast_environment_->PostTask(CastEnvironment::AUDIO, | 835 cast_environment_->PostTask(CastEnvironment::AUDIO, |
| 836 FROM_HERE, | 836 FROM_HERE, |
| 837 base::Bind(&AudioEncoder::ImplBase::EncodeAudio, | 837 base::Bind(&AudioEncoder::ImplBase::EncodeAudio, |
| 838 impl_, | 838 impl_, |
| 839 base::Passed(&audio_bus), | 839 base::Passed(&audio_bus), |
| 840 recorded_time)); | 840 recorded_time)); |
| 841 } | 841 } |
| 842 | 842 |
| 843 } // namespace cast | 843 } // namespace cast |
| 844 } // namespace media | 844 } // namespace media |
| OLD | NEW |