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

Side by Side Diff: media/base/audio_buffer_queue.cc

Issue 2466463005: Support (E)AC3 passthrough
Patch Set: Add unit tests Created 3 years, 6 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 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/base/audio_buffer_queue.h" 5 #include "media/base/audio_buffer_queue.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "media/base/audio_bus.h" 10 #include "media/base/audio_bus.h"
(...skipping 17 matching lines...) Expand all
28 current_buffer_ = buffers_.begin(); 28 current_buffer_ = buffers_.begin();
29 29
30 // Update the |frames_| counter since we have added frames. 30 // Update the |frames_| counter since we have added frames.
31 frames_ += buffer_in->frame_count(); 31 frames_ += buffer_in->frame_count();
32 CHECK_GT(frames_, 0); // make sure it doesn't overflow. 32 CHECK_GT(frames_, 0); // make sure it doesn't overflow.
33 } 33 }
34 34
35 int AudioBufferQueue::ReadFrames(int frames, 35 int AudioBufferQueue::ReadFrames(int frames,
36 int dest_frame_offset, 36 int dest_frame_offset,
37 AudioBus* dest) { 37 AudioBus* dest) {
38 DCHECK_GE(dest->frames(), frames + dest_frame_offset); 38 if (!dest->is_bitstream_format())
DaleCurtis 2017/06/15 21:46:32 Add corresponding dcheck for bitstream formats.
AndyWu 2017/08/02 01:43:40 Done.
39 DCHECK_GE(dest->frames(), frames + dest_frame_offset);
39 return InternalRead(frames, true, 0, dest_frame_offset, dest); 40 return InternalRead(frames, true, 0, dest_frame_offset, dest);
40 } 41 }
41 42
42 int AudioBufferQueue::PeekFrames(int frames, 43 int AudioBufferQueue::PeekFrames(int frames,
43 int source_frame_offset, 44 int source_frame_offset,
44 int dest_frame_offset, 45 int dest_frame_offset,
45 AudioBus* dest) { 46 AudioBus* dest) {
46 DCHECK_GE(dest->frames(), frames); 47 DCHECK_GE(dest->frames(), frames);
47 return InternalRead( 48 return InternalRead(
DaleCurtis 2017/06/15 21:46:32 DCHECK that this is never called with a bitstream
AndyWu 2017/08/02 01:43:40 Why do we need this restriction?
48 frames, false, source_frame_offset, dest_frame_offset, dest); 49 frames, false, source_frame_offset, dest_frame_offset, dest);
49 } 50 }
50 51
51 void AudioBufferQueue::SeekFrames(int frames) { 52 void AudioBufferQueue::SeekFrames(int frames) {
52 // Perform seek only if we have enough bytes in the queue. 53 // Perform seek only if we have enough bytes in the queue.
53 CHECK_LE(frames, frames_); 54 CHECK_LE(frames, frames_);
54 int taken = InternalRead(frames, true, 0, 0, NULL); 55 int taken = InternalRead(frames, true, 0, 0, NULL);
55 DCHECK_EQ(taken, frames); 56 DCHECK_EQ(taken, frames);
56 } 57 }
57 58
58 int AudioBufferQueue::InternalRead(int frames, 59 int AudioBufferQueue::InternalRead(int frames,
59 bool advance_position, 60 bool advance_position,
60 int source_frame_offset, 61 int source_frame_offset,
DaleCurtis 2017/06/15 21:46:32 Why do you need any changes here? If calling param
AndyWu 2017/08/02 01:43:40 For compressed bitstream formats, a partial compre
DaleCurtis 2017/08/03 01:38:10 I guess I meant why not just DCHECK() that you hav
AndyWu 2017/08/03 17:11:17 Unfortunately, we don't know the right parameter d
61 int dest_frame_offset, 62 int dest_frame_offset,
62 AudioBus* dest) { 63 AudioBus* dest) {
64 if (!buffers_.size())
DaleCurtis 2017/06/15 21:46:32 if buffers_.empty()
AndyWu 2017/08/02 01:43:40 Done.
65 return 0;
66
67 if ((*buffers_.begin())->IsBitstreamFormat()) {
chcunningham 2017/06/14 20:03:08 This block needs a comment to explain why |frames|
DaleCurtis 2017/06/15 21:46:32 Just buffers_.front()->IsBitstreamFormat()
AndyWu 2017/08/02 01:43:40 Done.
AndyWu 2017/08/02 01:43:40 Done.
68 DCHECK(!dest_frame_offset);
69 DCHECK(!source_frame_offset);
70
71 scoped_refptr<AudioBuffer> buffer = buffers_.front();
chcunningham 2017/06/14 20:03:08 Should you use current_buffer_ here to be consiste
AndyWu 2017/08/02 01:43:40 Done.
72 int taken = buffer->frame_count();
73
74 // if |dest| is NULL, there's no need to copy.
75 if (dest)
76 buffer->ReadFrames(buffer->frame_count(), 0, dest->data_size(), dest);
chcunningham 2017/06/14 20:03:08 Do you mean to pass dest->data_size() here? Should
AndyWu 2017/08/02 01:43:40 You are right! I was trying to append the data to
77
78 if (advance_position) {
79 // Update the appropriate values since |taken| frames have been copied
80 // out.
81 frames_ -= taken;
82 DCHECK_GE(frames_, 0);
83
84 // Remove any buffers before the current buffer as there is no going
85 // backwards.
86 buffers_.pop_front();
87 current_buffer_ = buffers_.begin();
88 }
89
90 return taken;
91 }
92
63 // Counts how many frames are actually read from the buffer queue. 93 // Counts how many frames are actually read from the buffer queue.
64 int taken = 0; 94 int taken = 0;
65 BufferQueue::iterator current_buffer = current_buffer_; 95 BufferQueue::iterator current_buffer = current_buffer_;
66 int current_buffer_offset = current_buffer_offset_; 96 int current_buffer_offset = current_buffer_offset_;
67 97
68 int frames_to_skip = source_frame_offset; 98 int frames_to_skip = source_frame_offset;
69 while (taken < frames) { 99 while (taken < frames) {
70 // |current_buffer| is valid since the first time this buffer is appended 100 // |current_buffer| is valid since the first time this buffer is appended
71 // with data. Make sure there is data to be processed. 101 // with data. Make sure there is data to be processed.
72 if (current_buffer == buffers_.end()) 102 if (current_buffer == buffers_.end())
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 // backwards. 157 // backwards.
128 buffers_.erase(buffers_.begin(), current_buffer); 158 buffers_.erase(buffers_.begin(), current_buffer);
129 current_buffer_ = buffers_.begin(); 159 current_buffer_ = buffers_.begin();
130 current_buffer_offset_ = current_buffer_offset; 160 current_buffer_offset_ = current_buffer_offset;
131 } 161 }
132 162
133 return taken; 163 return taken;
134 } 164 }
135 165
136 } // namespace media 166 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698