Chromium Code Reviews| Index: services/media/framework/models/lpcm_frames.h |
| diff --git a/services/media/framework/models/lpcm_frames.h b/services/media/framework/models/lpcm_frames.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..120e331c966dd2ca19d1df138dfb04d7039b56c8 |
| --- /dev/null |
| +++ b/services/media/framework/models/lpcm_frames.h |
| @@ -0,0 +1,90 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef MOJO_MEDIA_MODELS_LPCM_FRAMES_H_ |
| +#define MOJO_MEDIA_MODELS_LPCM_FRAMES_H_ |
| + |
| +#include <cstdint> |
| + |
| +#include "base/logging.h" |
| +#include "services/media/framework/packet.h" |
| + |
| +namespace mojo { |
| +namespace media { |
| + |
| +// References an LPCM frame buffer and implements advancement through it. |
| +class LpcmFrames { |
| + public: |
| + LpcmFrames() : |
| + bytes_per_frame_(0), |
| + remaining_buffer_(nullptr), |
| + remaining_frame_count_(0) {} |
| + |
| + void set_bytes_per_frame(uint32_t bytes_per_frame) { |
| + bytes_per_frame_ = bytes_per_frame; |
| + } |
| + |
| + uint32_t bytes_per_frame() { |
|
johngro
2016/01/26 01:32:39
this method is const. Same goes for the other acc
dalesat
2016/01/26 21:17:51
Good catch. Still not in the habit of looking for
|
| + return bytes_per_frame_; |
| + } |
| + |
| + // The remaining frame buffer. |
| + void* buffer() { |
| + return remaining_buffer_; |
| + } |
| + |
| + // The remaining number of frames accommodated by the frame buffer. |
| + uint64_t frame_count() { |
| + return remaining_frame_count_; |
| + } |
| + |
| + // Resets the buffer and frame. |
| + void reset() { |
| + remaining_buffer_ = nullptr; |
| + remaining_frame_count_ = 0; |
| + reset_when_exhausted_ = nullptr; |
| + } |
| + |
| + // Sets the buffer and frame count. |
| + void set(void* buffer, uint64_t frame_count) { |
| + remaining_buffer_ = buffer; |
| + remaining_frame_count_ = frame_count; |
| + reset_when_exhausted_ = nullptr; |
| + } |
| + |
| + void set(PacketPtr& packet) { |
| + DCHECK(packet); |
| + remaining_buffer_ = packet->payload(); |
| + remaining_frame_count_ = packet->duration(); |
| + if (remaining_frame_count_ == 0) { |
| + packet.reset(); |
| + reset_when_exhausted_ = nullptr; |
| + } else { |
| + reset_when_exhausted_ = &packet; |
| + } |
| + } |
| + |
| + // Updates buffer and frame_count to reflect use of the buffer. |
| + void advance(uint64_t frame_count) { |
| + DCHECK(remaining_buffer_); |
| + DCHECK(frame_count <= remaining_frame_count_); |
| + remaining_buffer_ = reinterpret_cast<uint8_t*>(remaining_buffer_) + |
| + (frame_count * bytes_per_frame_); |
| + remaining_frame_count_ -= frame_count; |
| + if (remaining_frame_count_ == 0 && reset_when_exhausted_ != nullptr) { |
| + (*reset_when_exhausted_).reset(); |
| + } |
| + } |
| + |
| + private: |
| + uint32_t bytes_per_frame_; |
| + void* remaining_buffer_; |
| + uint64_t remaining_frame_count_; |
| + PacketPtr* reset_when_exhausted_; |
|
johngro
2016/01/26 01:32:39
I'm unclear on why we need reset_when_exhausted_ h
dalesat
2016/01/26 21:17:51
This feature is used in LpcmStageInput, and the ha
johngro
2016/01/27 22:35:22
Acknowledged.
|
| +}; |
| + |
| +} // namespace media |
| +} // namespace mojo |
| + |
| +#endif // MOJO_MEDIA_MODELS_LPCM_FRAMES_H_ |