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 | /* vim:set ts=2 sw=2 sts=2 et cindent: */ |
michael@0 | 3 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | #if !defined(MediaMetadataManager_h__) |
michael@0 | 8 | #define MediaMetadataManager_h__ |
michael@0 | 9 | #include "VideoUtils.h" |
michael@0 | 10 | #include "mozilla/LinkedList.h" |
michael@0 | 11 | #include "AbstractMediaDecoder.h" |
michael@0 | 12 | #include "nsAutoPtr.h" |
michael@0 | 13 | |
michael@0 | 14 | namespace mozilla { |
michael@0 | 15 | |
michael@0 | 16 | // A struct that contains the metadata of a media, and the time at which those |
michael@0 | 17 | // metadata should start to be reported. |
michael@0 | 18 | class TimedMetadata : public LinkedListElement<TimedMetadata> { |
michael@0 | 19 | public: |
michael@0 | 20 | // The time, in microseconds, at which those metadata should be available. |
michael@0 | 21 | int64_t mPublishTime; |
michael@0 | 22 | // The metadata. The ownership is transfered to the element when dispatching to |
michael@0 | 23 | // the main threads. |
michael@0 | 24 | nsAutoPtr<MetadataTags> mTags; |
michael@0 | 25 | // The sample rate of this media. |
michael@0 | 26 | int mRate; |
michael@0 | 27 | // The number of channel of this media. |
michael@0 | 28 | int mChannels; |
michael@0 | 29 | // True if this media has an audio track. |
michael@0 | 30 | bool mHasAudio; |
michael@0 | 31 | // True if this media has a video track. |
michael@0 | 32 | bool mHasVideo; |
michael@0 | 33 | }; |
michael@0 | 34 | |
michael@0 | 35 | // This class encapsulate the logic to give the metadata from the reader to |
michael@0 | 36 | // the content, at the right time. |
michael@0 | 37 | class MediaMetadataManager |
michael@0 | 38 | { |
michael@0 | 39 | public: |
michael@0 | 40 | ~MediaMetadataManager() { |
michael@0 | 41 | TimedMetadata* element; |
michael@0 | 42 | while((element = mMetadataQueue.popFirst()) != nullptr) { |
michael@0 | 43 | delete element; |
michael@0 | 44 | } |
michael@0 | 45 | } |
michael@0 | 46 | void QueueMetadata(TimedMetadata* aMetadata) { |
michael@0 | 47 | mMetadataQueue.insertBack(aMetadata); |
michael@0 | 48 | } |
michael@0 | 49 | |
michael@0 | 50 | void DispatchMetadataIfNeeded(AbstractMediaDecoder* aDecoder, double aCurrentTime) { |
michael@0 | 51 | TimedMetadata* metadata = mMetadataQueue.getFirst(); |
michael@0 | 52 | while (metadata && aCurrentTime >= static_cast<double>(metadata->mPublishTime) / USECS_PER_S) { |
michael@0 | 53 | nsCOMPtr<nsIRunnable> metadataUpdatedEvent = |
michael@0 | 54 | new AudioMetadataEventRunner(aDecoder, |
michael@0 | 55 | metadata->mChannels, |
michael@0 | 56 | metadata->mRate, |
michael@0 | 57 | metadata->mHasAudio, |
michael@0 | 58 | metadata->mHasVideo, |
michael@0 | 59 | metadata->mTags.forget()); |
michael@0 | 60 | NS_DispatchToMainThread(metadataUpdatedEvent, NS_DISPATCH_NORMAL); |
michael@0 | 61 | delete mMetadataQueue.popFirst(); |
michael@0 | 62 | metadata = mMetadataQueue.getFirst(); |
michael@0 | 63 | } |
michael@0 | 64 | } |
michael@0 | 65 | protected: |
michael@0 | 66 | LinkedList<TimedMetadata> mMetadataQueue; |
michael@0 | 67 | }; |
michael@0 | 68 | } |
michael@0 | 69 | |
michael@0 | 70 | #endif |