michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-*/ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "WebMWriter.h" michael@0: #include "EbmlComposer.h" michael@0: michael@0: namespace mozilla { michael@0: michael@0: WebMWriter::WebMWriter(uint32_t aTrackTypes) : ContainerWriter() michael@0: { michael@0: mMetadataRequiredFlag = aTrackTypes; michael@0: mEbmlComposer = new EbmlComposer(); michael@0: } michael@0: michael@0: nsresult michael@0: WebMWriter::WriteEncodedTrack(const EncodedFrameContainer& aData, michael@0: uint32_t aFlags) michael@0: { michael@0: for (uint32_t i = 0 ; i < aData.GetEncodedFrames().Length(); i++) { michael@0: mEbmlComposer->WriteSimpleBlock(aData.GetEncodedFrames().ElementAt(i).get()); michael@0: } michael@0: return NS_OK; michael@0: } michael@0: michael@0: nsresult michael@0: WebMWriter::GetContainerData(nsTArray >* aOutputBufs, michael@0: uint32_t aFlags) michael@0: { michael@0: mEbmlComposer->ExtractBuffer(aOutputBufs, aFlags); michael@0: if (aFlags & ContainerWriter::FLUSH_NEEDED) { michael@0: mIsWritingComplete = true; michael@0: } michael@0: return NS_OK; michael@0: } michael@0: michael@0: nsresult michael@0: WebMWriter::SetMetadata(TrackMetadataBase* aMetadata) michael@0: { michael@0: MOZ_ASSERT(aMetadata); michael@0: if (aMetadata->GetKind() == TrackMetadataBase::METADATA_VP8) { michael@0: VP8Metadata* meta = static_cast(aMetadata); michael@0: MOZ_ASSERT(meta, "Cannot find vp8 encoder metadata"); michael@0: mEbmlComposer->SetVideoConfig(meta->mWidth, meta->mHeight, michael@0: meta->mDisplayWidth, meta->mDisplayHeight, michael@0: meta->mEncodedFrameRate); michael@0: mMetadataRequiredFlag = mMetadataRequiredFlag & ~ContainerWriter::CREATE_VIDEO_TRACK; michael@0: } michael@0: michael@0: if (aMetadata->GetKind() == TrackMetadataBase::METADATA_VORBIS) { michael@0: VorbisMetadata* meta = static_cast(aMetadata); michael@0: MOZ_ASSERT(meta, "Cannot find vorbis encoder metadata"); michael@0: mEbmlComposer->SetAudioConfig(meta->mSamplingFrequency, meta->mChannels, meta->mBitDepth); michael@0: mEbmlComposer->SetAudioCodecPrivateData(meta->mData); michael@0: mMetadataRequiredFlag = mMetadataRequiredFlag & ~ContainerWriter::CREATE_AUDIO_TRACK; michael@0: } michael@0: michael@0: if (!mMetadataRequiredFlag) { michael@0: mEbmlComposer->GenerateHeader(); michael@0: } michael@0: return NS_OK; michael@0: } michael@0: michael@0: } // mozilla namespace