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

Side by Side Diff: services/media/framework/lpcm_util.cc

Issue 1577953002: Motown in-proc streaming framework used to implement media services. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: removed build/util/LASTCHANGE 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 #include "base/logging.h"
6 #include "services/media/framework/lpcm_util.h"
7 #include "services/media/framework/ostream.h"
8
9 namespace mojo {
10 namespace media {
11
12 LpcmUtil* LpcmUtil::Create(const LpcmStreamType& stream_type) {
13 switch (stream_type.sample_format()) {
14 case LpcmStreamType::SampleFormat::kUnsigned8:
15 case LpcmStreamType::SampleFormat::kAny:
16 return new LpcmUtilImpl<uint8_t>(stream_type);
17 case LpcmStreamType::SampleFormat::kSigned16:
18 return new LpcmUtilImpl<int16_t>(stream_type);
19 case LpcmStreamType::SampleFormat::kSigned24In32:
20 return new LpcmUtilImpl<int32_t>(stream_type);
21 case LpcmStreamType::SampleFormat::kFloat:
22 return new LpcmUtilImpl<float>(stream_type);
23 default:
24 NOTREACHED()
25 << "unsupported sample format " << stream_type.sample_format();
26 return nullptr;
27 }
28 }
29
30 template<typename T>
31 LpcmUtilImpl<T>::LpcmUtilImpl(const LpcmStreamType& stream_type) :
32 stream_type_(stream_type) {}
33
34 template<typename T>
35 LpcmUtilImpl<T>::~LpcmUtilImpl() {}
36
37 template<typename T>
38 void LpcmUtilImpl<T>::Silence(void* buffer, uint64_t frame_count) const {
johngro 2016/01/25 18:55:43 for the cases of filling a non-float, signed buffe
dalesat 2016/01/25 23:29:37 Done.
39 T* sample = reinterpret_cast<T*>(buffer);
40 for (
41 uint64_t sample_countdown = frame_count * stream_type_.channels();
42 sample_countdown != 0;
43 --sample_countdown) {
44 *sample = 0;
45 sample++;
46 }
47 }
48
49 template<>
50 void LpcmUtilImpl<uint8_t>::Silence(void* buffer, uint64_t frame_count) const {
51 uint8_t* sample = reinterpret_cast<uint8_t*>(buffer);
52 for (
53 uint64_t sample_countdown = frame_count * stream_type_.channels();
54 sample_countdown != 0;
55 --sample_countdown) {
56 *sample = 0x80;
57 sample++;
58 }
59 }
60
61 template<typename T>
62 void LpcmUtilImpl<T>::Copy(void* in, void* out, uint64_t frame_count) const {
63 std::memcpy(out, in, stream_type_.min_buffer_size(frame_count));
64 }
65
66 template<typename T>
67 void LpcmUtilImpl<T>::Mix(void* in, void* out, uint64_t frame_count) const {
68 T* in_sample = reinterpret_cast<T*>(in);
69 T* out_sample = reinterpret_cast<T*>(out);
70 for (
71 uint64_t sample_countdown = frame_count * stream_type_.channels();
72 sample_countdown != 0;
73 --sample_countdown) {
74 *out_sample += *in_sample; // TODO(dalesat): Limit.
75 out_sample++;
76 in_sample++;
77 }
78 }
79
80 template<>
81 void LpcmUtilImpl<uint8_t>::Mix(void* in, void* out, uint64_t frame_count)
82 const {
83 uint8_t* in_sample = reinterpret_cast<uint8_t*>(in);
84 uint8_t* out_sample = reinterpret_cast<uint8_t*>(out);
85 for (
86 uint64_t sample_countdown = frame_count * stream_type_.channels();
87 sample_countdown != 0;
88 --sample_countdown) {
89 *out_sample = uint8_t(uint16_t(*out_sample) + uint16_t(*in_sample) - 0x80);
90 // TODO(dalesat): Limit.
91 out_sample++;
92 in_sample++;
93 }
94 }
95
96 template<typename T>
97 void LpcmUtilImpl<T>::Interleave(
98 void* in,
99 uint64_t in_byte_count,
100 void* out,
101 uint64_t frame_count) const {
102 DCHECK(in);
103 DCHECK(in_byte_count);
104 DCHECK(out);
105 DCHECK(frame_count);
106
107 uint32_t channels = stream_type_.channels();
108 uint64_t in_channel_stride = in_byte_count / channels;
johngro 2016/01/25 18:55:43 see comment in header re: in_byte_count. That sai
dalesat 2016/01/25 23:29:37 Done.
109
110 uint8_t* in_channel = reinterpret_cast<uint8_t*>(in);
111 uint8_t* out_channel = reinterpret_cast<uint8_t*>(out);
112
113 for (uint32_t channel = channels; channel != 0; --channel) {
114 T* in_sample = reinterpret_cast<T*>(in_channel);
115 T* out_sample = reinterpret_cast<T*>(out_channel);
116 for (uint64_t frame = frame_count; frame != 0; --frame) {
117 *out_sample = *in_sample;
118 ++in_sample;
119 out_sample += channels;
120 }
121 in_channel += in_channel_stride;
122 out_channel += stream_type_.sample_size();
123 }
124 }
125
126 } // namespace media
127 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698