Skip to content

Commit

Permalink
Work in progress: OggDemuxer and TheoraDecoder
Browse files Browse the repository at this point in the history
OggDemuxer is still incomplete and has lots of
stray debug stuff & copypasta code from WebMDemuxer

Can be flipped in/out via config: media.format-reader.ogg
  • Loading branch information
bvibber committed Nov 7, 2015
1 parent 10e4bb4 commit b200af9
Show file tree
Hide file tree
Showing 13 changed files with 1,752 additions and 44 deletions.
5 changes: 4 additions & 1 deletion dom/media/DecoderTraits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include "OggDecoder.h"
#include "OggReader.h"
#include "OggDemuxer.h"
#ifdef MOZ_WAVE
#include "WaveDecoder.h"
#include "WaveReader.h"
Expand Down Expand Up @@ -723,7 +724,9 @@ MediaDecoderReader* DecoderTraits::CreateReader(const nsACString& aType, Abstrac
} else
#endif
if (IsOggType(aType)) {
decoderReader = new OggReader(aDecoder);
decoderReader = Preferences::GetBool("media.format-reader.ogg", true) ?
static_cast<MediaDecoderReader*>(new MediaFormatReader(aDecoder, new OggDemuxer(aDecoder->GetResource()))) :
new OggReader(aDecoder);
} else
#ifdef MOZ_WAVE
if (IsWaveType(aType)) {
Expand Down
37 changes: 37 additions & 0 deletions dom/media/ogg/OggCodecStore.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et cindent: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "mozilla/DebugOnly.h"

#include "OggCodecStore.h"

namespace mozilla {

OggCodecStore::OggCodecStore()
: mMonitor("CodecStore")
{
}

void OggCodecStore::Add(uint32_t serial, OggCodecState* codecState)
{
MonitorAutoLock mon(mMonitor);
mCodecStates.Put(serial, codecState);
}

bool OggCodecStore::Contains(uint32_t serial)
{
MonitorAutoLock mon(mMonitor);
return mCodecStates.Get(serial, nullptr);
}

OggCodecState* OggCodecStore::Get(uint32_t serial)
{
MonitorAutoLock mon(mMonitor);
return mCodecStates.Get(serial);
}

} // namespace mozilla

38 changes: 38 additions & 0 deletions dom/media/ogg/OggCodecStore.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et cindent: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#if !defined(OggCodecStore_h_)
#define OggCodecStore_h_

#include <ogg/ogg.h>

#include "OggCodecState.h"
#include "VideoUtils.h"
#include "mozilla/Monitor.h"

namespace mozilla {

// Thread safe container to store the codec information and the serial for each
// streams.
class OggCodecStore
{
public:
OggCodecStore();
void Add(uint32_t serial, OggCodecState* codecState);
bool Contains(uint32_t serial);
OggCodecState* Get(uint32_t serial);
bool IsKnownStream(uint32_t aSerial);

private:
// Maps Ogg serialnos to OggStreams.
nsClassHashtable<nsUint32HashKey, OggCodecState> mCodecStates;

// Protects the |mCodecStates| and the |mKnownStreams| members.
Monitor mMonitor;
};

} // namespace mozilla

#endif
10 changes: 9 additions & 1 deletion dom/media/ogg/OggDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,23 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "mozilla/Preferences.h"
#include "MediaDecoderStateMachine.h"
#include "MediaFormatReader.h"
#include "OggDemuxer.h"
#include "OggReader.h"
#include "OggDecoder.h"

namespace mozilla {

MediaDecoderStateMachine* OggDecoder::CreateStateMachine()
{
return new MediaDecoderStateMachine(this, new OggReader(this));
bool useFormatDecoder =
Preferences::GetBool("media.format-reader.ogg", true);
RefPtr<MediaDecoderReader> reader = useFormatDecoder ?
static_cast<MediaDecoderReader*>(new MediaFormatReader(this, new OggDemuxer(GetResource()))) :
new OggReader(this);
return new MediaDecoderStateMachine(this, reader);
}

} // namespace mozilla
Loading

0 comments on commit b200af9

Please sign in to comment.