OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 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 #ifndef MOJO_MEDIA_MODELS_LPCM_FRAMES_H_ | |
6 #define MOJO_MEDIA_MODELS_LPCM_FRAMES_H_ | |
7 | |
8 #include <cstdint> | |
9 #include <functional> | |
10 | |
11 #include "base/logging.h" | |
12 | |
13 namespace mojo { | |
14 namespace media { | |
15 | |
16 // References an LPCM frame buffer and implements advancement through it. | |
17 class LpcmFrames { | |
jeffbrown
2016/02/02 05:35:47
LpcmFrameBuffer? LpcmBuffer?
dalesat
2016/02/02 21:46:39
LpcmFrameBuffer. Done.
| |
18 public: | |
19 using ExhaustedCallback = std::function<void()>; | |
20 | |
21 LpcmFrames(); | |
22 | |
23 ~LpcmFrames(); | |
24 | |
25 void set_bytes_per_frame(uint32_t bytes_per_frame) { | |
26 bytes_per_frame_ = bytes_per_frame; | |
27 } | |
28 | |
29 uint32_t bytes_per_frame() const { | |
30 return bytes_per_frame_; | |
31 } | |
32 | |
33 // The remaining frame buffer. | |
34 void* buffer() const { | |
35 return remaining_buffer_; | |
36 } | |
37 | |
38 // The remaining number of frames accommodated by the frame buffer. | |
39 uint64_t frame_count() const { | |
40 return remaining_frame_count_; | |
41 } | |
42 | |
43 // Resets the buffer and frame. | |
44 void reset() { | |
jeffbrown
2016/02/02 05:35:47
These methods aren't simple accessors. Call them
dalesat
2016/02/02 21:46:39
Done.
| |
45 remaining_buffer_ = nullptr; | |
46 remaining_frame_count_ = 0; | |
47 exhausted_callback_ = nullptr; | |
48 } | |
49 | |
50 // Sets the buffer and frame count. | |
51 void set( | |
52 void* buffer, | |
53 uint64_t frame_count, | |
54 ExhaustedCallback exhausted_callback = nullptr) { | |
55 remaining_buffer_ = buffer; | |
56 remaining_frame_count_ = frame_count; | |
57 exhausted_callback_ = exhausted_callback; | |
58 } | |
59 | |
60 // Updates buffer and frame_count to reflect use of the buffer. | |
61 void advance(uint64_t frame_count) { | |
62 DCHECK(remaining_buffer_); | |
63 DCHECK(frame_count <= remaining_frame_count_); | |
64 remaining_buffer_ = reinterpret_cast<uint8_t*>(remaining_buffer_) + | |
65 (frame_count * bytes_per_frame_); | |
66 remaining_frame_count_ -= frame_count; | |
67 if (remaining_frame_count_ == 0 && exhausted_callback_ != nullptr) { | |
68 exhausted_callback_(); | |
69 exhausted_callback_ = nullptr; | |
70 } | |
71 } | |
72 | |
73 private: | |
74 uint32_t bytes_per_frame_; | |
75 void* remaining_buffer_; | |
76 uint64_t remaining_frame_count_; | |
77 ExhaustedCallback exhausted_callback_; | |
78 }; | |
79 | |
80 } // namespace media | |
81 } // namespace mojo | |
82 | |
83 #endif // MOJO_MEDIA_MODELS_LPCM_FRAMES_H_ | |
OLD | NEW |