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

Side by Side Diff: media/capture/webm_muxer.cc

Issue 1542013004: Switch to standard integer types in media/, take 2. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: more stddef Created 5 years 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
« no previous file with comments | « media/capture/webm_muxer.h ('k') | media/capture/webm_muxer_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "media/capture/webm_muxer.h" 5 #include "media/capture/webm_muxer.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "media/audio/audio_parameters.h" 8 #include "media/audio/audio_parameters.h"
9 #include "media/base/limits.h" 9 #include "media/base/limits.h"
10 #include "media/base/video_frame.h" 10 #include "media/base/video_frame.h"
11 #include "media/filters/opus_constants.h" 11 #include "media/filters/opus_constants.h"
12 #include "ui/gfx/geometry/size.h" 12 #include "ui/gfx/geometry/size.h"
13 13
14 namespace media { 14 namespace media {
15 15
16 namespace { 16 namespace {
17 17
18 void WriteOpusHeader(const media::AudioParameters& params, uint8* header) { 18 void WriteOpusHeader(const media::AudioParameters& params, uint8_t* header) {
19 // See https://wiki.xiph.org/OggOpus#ID_Header. 19 // See https://wiki.xiph.org/OggOpus#ID_Header.
20 // Set magic signature. 20 // Set magic signature.
21 std::string label = "OpusHead"; 21 std::string label = "OpusHead";
22 memcpy(header + OPUS_EXTRADATA_LABEL_OFFSET, label.c_str(), label.size()); 22 memcpy(header + OPUS_EXTRADATA_LABEL_OFFSET, label.c_str(), label.size());
23 // Set Opus version. 23 // Set Opus version.
24 header[OPUS_EXTRADATA_VERSION_OFFSET] = 1; 24 header[OPUS_EXTRADATA_VERSION_OFFSET] = 1;
25 // Set channel count. 25 // Set channel count.
26 header[OPUS_EXTRADATA_CHANNELS_OFFSET] = params.channels(); 26 header[OPUS_EXTRADATA_CHANNELS_OFFSET] = params.channels();
27 // Set pre-skip 27 // Set pre-skip
28 uint16 skip = 0; 28 uint16_t skip = 0;
29 memcpy(header + OPUS_EXTRADATA_SKIP_SAMPLES_OFFSET, &skip, sizeof(uint16)); 29 memcpy(header + OPUS_EXTRADATA_SKIP_SAMPLES_OFFSET, &skip, sizeof(uint16_t));
30 // Set original input sample rate in Hz. 30 // Set original input sample rate in Hz.
31 uint32 sample_rate = params.sample_rate(); 31 uint32_t sample_rate = params.sample_rate();
32 memcpy(header + OPUS_EXTRADATA_SAMPLE_RATE_OFFSET, &sample_rate, 32 memcpy(header + OPUS_EXTRADATA_SAMPLE_RATE_OFFSET, &sample_rate,
33 sizeof(uint32)); 33 sizeof(uint32_t));
34 // Set output gain in dB. 34 // Set output gain in dB.
35 uint16 gain = 0; 35 uint16_t gain = 0;
36 memcpy(header + OPUS_EXTRADATA_GAIN_OFFSET, &gain, 2); 36 memcpy(header + OPUS_EXTRADATA_GAIN_OFFSET, &gain, 2);
37 37
38 // Set channel mapping. 38 // Set channel mapping.
39 if (params.channels() > 2) { 39 if (params.channels() > 2) {
40 // Also possible to have a multistream, not supported for now. 40 // Also possible to have a multistream, not supported for now.
41 DCHECK_LE(params.channels(), OPUS_MAX_VORBIS_CHANNELS); 41 DCHECK_LE(params.channels(), OPUS_MAX_VORBIS_CHANNELS);
42 header[OPUS_EXTRADATA_CHANNEL_MAPPING_OFFSET] = 1; 42 header[OPUS_EXTRADATA_CHANNEL_MAPPING_OFFSET] = 1;
43 // Assuming no coupled streams. This should actually be 43 // Assuming no coupled streams. This should actually be
44 // channels() - |coupled_streams|. 44 // channels() - |coupled_streams|.
45 header[OPUS_EXTRADATA_NUM_STREAMS_OFFSET] = params.channels(); 45 header[OPUS_EXTRADATA_NUM_STREAMS_OFFSET] = params.channels();
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 210
211 mkvmuxer::AudioTrack* const audio_track = 211 mkvmuxer::AudioTrack* const audio_track =
212 reinterpret_cast<mkvmuxer::AudioTrack*>( 212 reinterpret_cast<mkvmuxer::AudioTrack*>(
213 segment_.GetTrackByNumber(audio_track_index_)); 213 segment_.GetTrackByNumber(audio_track_index_));
214 DCHECK(audio_track); 214 DCHECK(audio_track);
215 audio_track->set_codec_id(mkvmuxer::Tracks::kOpusCodecId); 215 audio_track->set_codec_id(mkvmuxer::Tracks::kOpusCodecId);
216 216
217 DCHECK_EQ(params.sample_rate(), audio_track->sample_rate()); 217 DCHECK_EQ(params.sample_rate(), audio_track->sample_rate());
218 DCHECK_EQ(params.channels(), static_cast<int>(audio_track->channels())); 218 DCHECK_EQ(params.channels(), static_cast<int>(audio_track->channels()));
219 219
220 uint8 opus_header[OPUS_EXTRADATA_SIZE]; 220 uint8_t opus_header[OPUS_EXTRADATA_SIZE];
221 WriteOpusHeader(params, opus_header); 221 WriteOpusHeader(params, opus_header);
222 222
223 if (!audio_track->SetCodecPrivate(opus_header, OPUS_EXTRADATA_SIZE)) 223 if (!audio_track->SetCodecPrivate(opus_header, OPUS_EXTRADATA_SIZE))
224 LOG(ERROR) << __FUNCTION__ << ": failed to set opus header."; 224 LOG(ERROR) << __FUNCTION__ << ": failed to set opus header.";
225 225
226 // Segment's timestamps should be in milliseconds, DCHECK it. See 226 // Segment's timestamps should be in milliseconds, DCHECK it. See
227 // http://www.webmproject.org/docs/container/#muxer-guidelines 227 // http://www.webmproject.org/docs/container/#muxer-guidelines
228 DCHECK_EQ(1000000ull, segment_.GetSegmentInfo()->timecode_scale()); 228 DCHECK_EQ(1000000ull, segment_.GetSegmentInfo()->timecode_scale());
229 } 229 }
230 230
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 std::max(most_recent_timestamp_, timestamp - first_frame_timestamp_); 269 std::max(most_recent_timestamp_, timestamp - first_frame_timestamp_);
270 270
271 segment_.AddFrame(reinterpret_cast<const uint8_t*>(encoded_data->data()), 271 segment_.AddFrame(reinterpret_cast<const uint8_t*>(encoded_data->data()),
272 encoded_data->size(), track_index, 272 encoded_data->size(), track_index,
273 most_recent_timestamp_.InMicroseconds() * 273 most_recent_timestamp_.InMicroseconds() *
274 base::Time::kNanosecondsPerMicrosecond, 274 base::Time::kNanosecondsPerMicrosecond,
275 is_key_frame); 275 is_key_frame);
276 } 276 }
277 277
278 } // namespace media 278 } // namespace media
OLDNEW
« no previous file with comments | « media/capture/webm_muxer.h ('k') | media/capture/webm_muxer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698