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

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: Changed lpcm input/output to use packets for supplying frames. Some name changes. Synced to master. 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() {
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
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 remaining_buffer_ = packet->payload();
59 remaining_frame_count_ = packet->duration();
60 if (remaining_frame_count_ == 0) {
61 packet.reset();
62 reset_when_exhausted_ = nullptr;
63 } else {
64 reset_when_exhausted_ = &packet;
65 }
66 }
67
68 // Updates buffer and frame_count to reflect use of the buffer.
69 void advance(uint64_t frame_count) {
70 DCHECK(remaining_buffer_);
71 DCHECK(frame_count <= remaining_frame_count_);
72 remaining_buffer_ = reinterpret_cast<uint8_t*>(remaining_buffer_) +
73 (frame_count * bytes_per_frame_);
74 remaining_frame_count_ -= frame_count;
75 if (remaining_frame_count_ == 0 && reset_when_exhausted_ != nullptr) {
76 (*reset_when_exhausted_).reset();
77 }
78 }
79
80 private:
81 uint32_t bytes_per_frame_;
82 void* remaining_buffer_;
83 uint64_t remaining_frame_count_;
84 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.
85 };
86
87 } // namespace media
88 } // namespace mojo
89
90 #endif // MOJO_MEDIA_MODELS_LPCM_FRAMES_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698