Fri, 16 Jan 2015 04:50:19 +0100
Replace accessor implementation with direct member state manipulation, by
request https://trac.torproject.org/projects/tor/ticket/9701#comment:32
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-*/ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
michael@0 | 4 | * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #include "WebMWriter.h" |
michael@0 | 7 | #include "EbmlComposer.h" |
michael@0 | 8 | |
michael@0 | 9 | namespace mozilla { |
michael@0 | 10 | |
michael@0 | 11 | WebMWriter::WebMWriter(uint32_t aTrackTypes) : ContainerWriter() |
michael@0 | 12 | { |
michael@0 | 13 | mMetadataRequiredFlag = aTrackTypes; |
michael@0 | 14 | mEbmlComposer = new EbmlComposer(); |
michael@0 | 15 | } |
michael@0 | 16 | |
michael@0 | 17 | nsresult |
michael@0 | 18 | WebMWriter::WriteEncodedTrack(const EncodedFrameContainer& aData, |
michael@0 | 19 | uint32_t aFlags) |
michael@0 | 20 | { |
michael@0 | 21 | for (uint32_t i = 0 ; i < aData.GetEncodedFrames().Length(); i++) { |
michael@0 | 22 | mEbmlComposer->WriteSimpleBlock(aData.GetEncodedFrames().ElementAt(i).get()); |
michael@0 | 23 | } |
michael@0 | 24 | return NS_OK; |
michael@0 | 25 | } |
michael@0 | 26 | |
michael@0 | 27 | nsresult |
michael@0 | 28 | WebMWriter::GetContainerData(nsTArray<nsTArray<uint8_t> >* aOutputBufs, |
michael@0 | 29 | uint32_t aFlags) |
michael@0 | 30 | { |
michael@0 | 31 | mEbmlComposer->ExtractBuffer(aOutputBufs, aFlags); |
michael@0 | 32 | if (aFlags & ContainerWriter::FLUSH_NEEDED) { |
michael@0 | 33 | mIsWritingComplete = true; |
michael@0 | 34 | } |
michael@0 | 35 | return NS_OK; |
michael@0 | 36 | } |
michael@0 | 37 | |
michael@0 | 38 | nsresult |
michael@0 | 39 | WebMWriter::SetMetadata(TrackMetadataBase* aMetadata) |
michael@0 | 40 | { |
michael@0 | 41 | MOZ_ASSERT(aMetadata); |
michael@0 | 42 | if (aMetadata->GetKind() == TrackMetadataBase::METADATA_VP8) { |
michael@0 | 43 | VP8Metadata* meta = static_cast<VP8Metadata*>(aMetadata); |
michael@0 | 44 | MOZ_ASSERT(meta, "Cannot find vp8 encoder metadata"); |
michael@0 | 45 | mEbmlComposer->SetVideoConfig(meta->mWidth, meta->mHeight, |
michael@0 | 46 | meta->mDisplayWidth, meta->mDisplayHeight, |
michael@0 | 47 | meta->mEncodedFrameRate); |
michael@0 | 48 | mMetadataRequiredFlag = mMetadataRequiredFlag & ~ContainerWriter::CREATE_VIDEO_TRACK; |
michael@0 | 49 | } |
michael@0 | 50 | |
michael@0 | 51 | if (aMetadata->GetKind() == TrackMetadataBase::METADATA_VORBIS) { |
michael@0 | 52 | VorbisMetadata* meta = static_cast<VorbisMetadata*>(aMetadata); |
michael@0 | 53 | MOZ_ASSERT(meta, "Cannot find vorbis encoder metadata"); |
michael@0 | 54 | mEbmlComposer->SetAudioConfig(meta->mSamplingFrequency, meta->mChannels, meta->mBitDepth); |
michael@0 | 55 | mEbmlComposer->SetAudioCodecPrivateData(meta->mData); |
michael@0 | 56 | mMetadataRequiredFlag = mMetadataRequiredFlag & ~ContainerWriter::CREATE_AUDIO_TRACK; |
michael@0 | 57 | } |
michael@0 | 58 | |
michael@0 | 59 | if (!mMetadataRequiredFlag) { |
michael@0 | 60 | mEbmlComposer->GenerateHeader(); |
michael@0 | 61 | } |
michael@0 | 62 | return NS_OK; |
michael@0 | 63 | } |
michael@0 | 64 | |
michael@0 | 65 | } // mozilla namespace |