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

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

Issue 389623002: Add a block based Audio FIFO. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: addressed the comments. Created 6 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "media/base/audio_block_fifo.h"
6
7 #include "base/logging.h"
8
9 namespace media {
10
11 AudioBlockFifo::AudioBlockFifo(int channels, int frames, int blocks)
12 : block_frames_(frames),
13 write_pos_(0) {
14 // Create |blocks| of audio buses and push them to the containers.
DaleCurtis 2014/07/14 20:14:27 Since you know the capacity, call audio_blocks_.re
no longer working on chromium 2014/07/15 21:43:13 Done.
15 for (int i = 0; i < blocks; ++i) {
16 scoped_ptr<AudioBus> audio_bus = AudioBus::Create(channels, frames);
17 audio_blocks_.push_back(audio_bus.release());
18 unfilled_blocks_.push(audio_blocks_.back());
19 }
20 }
21
22 AudioBlockFifo::~AudioBlockFifo() {}
23
24 void AudioBlockFifo::Push(const void* source, int frames,
DaleCurtis 2014/07/14 20:14:27 Is this actually allowed clang-format style? I tho
no longer working on chromium 2014/07/15 21:43:13 I saw both in the current chromium code, so I gues
25 int bytes_per_sample) {
26 DCHECK(source);
27 DCHECK_GT(frames, 0);
28 DCHECK_GT(bytes_per_sample, 0);
29
30 const uint8* source_ptr = static_cast<const uint8*>(source);
31 int frames_to_push = frames;
32 while (frames_to_push) {
33 // Get the current write block.
34 AudioBus* current_block = unfilled_blocks_.front();
35 CHECK(current_block);
DaleCurtis 2014/07/14 20:14:27 Seems unnecessary? Just add a DCHECK(!unfilled_bl
no longer working on chromium 2014/07/15 21:43:13 Done.
36 DCHECK_EQ(current_block->frames(), block_frames_);
37
38 // Figure out what segment sizes we need when adding the new content to
39 // the FIFO.
40 const int push_frames =
41 std::min(block_frames_ - write_pos_, frames_to_push);
42
43 // Deinterleave the content to the FIFO and update the |write_pos_|.
44 current_block->FromInterleaved(source_ptr, push_frames, bytes_per_sample);
45 write_pos_ = (write_pos_ + push_frames) % block_frames_;
46 if (!write_pos_) {
47 // The current block is completely filled, move it from |empety_blocks_|
DaleCurtis 2014/07/14 20:14:27 empty_blocks_
no longer working on chromium 2014/07/15 21:43:12 comment was updated.
48 // to |filled_blocks_|.
49 filled_blocks_.push(current_block);
50 unfilled_blocks_.pop();
51 }
52
53 source_ptr += push_frames * bytes_per_sample * current_block->channels();
54 frames_to_push -= push_frames;
55 }
56 }
57
58 const AudioBus* AudioBlockFifo::Consume() {
59 DCHECK(available_blocks());
60 AudioBus* audio_bus = filled_blocks_.front();
61 unfilled_blocks_.push(audio_bus);
62 filled_blocks_.pop();
63 return audio_bus;
64 }
65
66 void AudioBlockFifo::Clear() {
67 write_pos_ = 0;
68 while (!filled_blocks_.empty()) {
69 AudioBus* audio_bus = filled_blocks_.front();
70 unfilled_blocks_.push(audio_bus);
71 filled_blocks_.pop();
72 }
73 }
74
75 int AudioBlockFifo::unfilled_frames() const {
76 DCHECK_GE(static_cast<int>(unfilled_blocks_.size() * block_frames_),
DaleCurtis 2014/07/14 20:14:27 Since you're making calculations here, this can't
no longer working on chromium 2014/07/15 21:43:13 GetUnfilledFrames() sounds good since available_bl
77 write_pos_);
78 return unfilled_blocks_.size() * block_frames_ - write_pos_;
79 }
80
81 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698