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

Side by Side Diff: services/media/framework/models/lpcm_frames.h

Issue 1577953002: Motown in-proc streaming framework used to implement media services. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Addressed feedback including non-const ref parameters. Created 4 years, 11 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
(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
10 #include "base/logging.h"
11 #include "services/media/framework/packet.h"
12
13 namespace mojo {
14 namespace media {
15
16 // References an LPCM frame buffer and implements advancement through it.
17 class LpcmFrames {
18 public:
19 LpcmFrames() :
20 bytes_per_frame_(0),
21 remaining_buffer_(nullptr),
22 remaining_frame_count_(0) {}
23
24 void set_bytes_per_frame(uint32_t bytes_per_frame) {
25 bytes_per_frame_ = bytes_per_frame;
26 }
27
28 uint32_t bytes_per_frame() {
29 return bytes_per_frame_;
30 }
31
32 // The remaining frame buffer.
33 void* buffer() {
34 return remaining_buffer_;
35 }
36
37 // The remaining number of frames accommodated by the frame buffer.
38 uint64_t frame_count() {
39 return remaining_frame_count_;
40 }
41
42 // Resets the buffer and frame.
43 void reset() {
44 remaining_buffer_ = nullptr;
45 remaining_frame_count_ = 0;
46 reset_when_exhausted_ = nullptr;
47 }
48
49 // Sets the buffer and frame count.
50 void set(void* buffer, uint64_t frame_count) {
51 remaining_buffer_ = buffer;
52 remaining_frame_count_ = frame_count;
53 reset_when_exhausted_ = nullptr;
54 }
55
56 void set(PacketPtr* packet) {
57 DCHECK(packet);
58 DCHECK(*packet);
59 remaining_buffer_ = (*packet)->payload();
60 remaining_frame_count_ = (*packet)->duration();
61 if (remaining_frame_count_ == 0) {
62 packet->reset();
63 reset_when_exhausted_ = nullptr;
64 } else {
65 reset_when_exhausted_ = packet;
66 }
67 }
68
69 // Updates buffer and frame_count to reflect use of the buffer.
70 void advance(uint64_t frame_count) {
71 DCHECK(remaining_buffer_);
72 DCHECK(frame_count <= remaining_frame_count_);
73 remaining_buffer_ = reinterpret_cast<uint8_t*>(remaining_buffer_) +
74 (frame_count * bytes_per_frame_);
75 remaining_frame_count_ -= frame_count;
76 if (remaining_frame_count_ == 0 && reset_when_exhausted_ != nullptr) {
77 (*reset_when_exhausted_).reset();
78 }
79 }
80
81 private:
82 uint32_t bytes_per_frame_;
83 void* remaining_buffer_;
84 uint64_t remaining_frame_count_;
85 PacketPtr* reset_when_exhausted_;
86 };
87
88 } // namespace media
89 } // namespace mojo
90
91 #endif // MOJO_MEDIA_MODELS_LPCM_FRAMES_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698