Fri, 16 Jan 2015 18:13:44 +0100
Integrate suggestion from review to improve consistency with existing code.
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 file, |
michael@0 | 5 | * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | #if !defined(RtspOmxReader_h_) |
michael@0 | 7 | #define RtspOmxReader_h_ |
michael@0 | 8 | |
michael@0 | 9 | #include "MediaResource.h" |
michael@0 | 10 | #include "MediaDecoderReader.h" |
michael@0 | 11 | #include "MediaOmxReader.h" |
michael@0 | 12 | |
michael@0 | 13 | namespace mozilla { |
michael@0 | 14 | |
michael@0 | 15 | namespace dom { |
michael@0 | 16 | class TimeRanges; |
michael@0 | 17 | } |
michael@0 | 18 | |
michael@0 | 19 | class AbstractMediaDecoder; |
michael@0 | 20 | class RtspMediaResource; |
michael@0 | 21 | |
michael@0 | 22 | /* RtspOmxReader is a subclass of MediaOmxReader. |
michael@0 | 23 | * The major reason that RtspOmxReader inherit from MediaOmxReader is the |
michael@0 | 24 | * same video/audio decoding logic we can reuse. |
michael@0 | 25 | */ |
michael@0 | 26 | class RtspOmxReader : public MediaOmxReader |
michael@0 | 27 | { |
michael@0 | 28 | protected: |
michael@0 | 29 | // Provide a Rtsp extractor. |
michael@0 | 30 | nsresult InitOmxDecoder() MOZ_FINAL MOZ_OVERRIDE; |
michael@0 | 31 | |
michael@0 | 32 | public: |
michael@0 | 33 | RtspOmxReader(AbstractMediaDecoder* aDecoder) |
michael@0 | 34 | : MediaOmxReader(aDecoder) { |
michael@0 | 35 | MOZ_COUNT_CTOR(RtspOmxReader); |
michael@0 | 36 | NS_ASSERTION(mDecoder, "RtspOmxReader mDecoder is null."); |
michael@0 | 37 | NS_ASSERTION(mDecoder->GetResource(), |
michael@0 | 38 | "RtspOmxReader mDecoder->GetResource() is null."); |
michael@0 | 39 | mRtspResource = mDecoder->GetResource()->GetRtspPointer(); |
michael@0 | 40 | MOZ_ASSERT(mRtspResource); |
michael@0 | 41 | } |
michael@0 | 42 | |
michael@0 | 43 | virtual ~RtspOmxReader() MOZ_OVERRIDE { |
michael@0 | 44 | MOZ_COUNT_DTOR(RtspOmxReader); |
michael@0 | 45 | } |
michael@0 | 46 | |
michael@0 | 47 | virtual nsresult ReadMetadata(MediaInfo* aInfo, |
michael@0 | 48 | MetadataTags** aTags) MOZ_OVERRIDE; |
michael@0 | 49 | |
michael@0 | 50 | // Implement a time-based seek instead of byte-based.. |
michael@0 | 51 | virtual nsresult Seek(int64_t aTime, int64_t aStartTime, int64_t aEndTime, |
michael@0 | 52 | int64_t aCurrentTime) MOZ_FINAL MOZ_OVERRIDE; |
michael@0 | 53 | |
michael@0 | 54 | // Override GetBuffered() to do nothing for below reasons: |
michael@0 | 55 | // 1. Because the Rtsp stream is a/v separated. The buffered data in a/v |
michael@0 | 56 | // tracks are not consistent with time stamp. |
michael@0 | 57 | // For example: audio buffer: 1~2s, video buffer: 1.5~2.5s |
michael@0 | 58 | // 2. Since the Rtsp is a realtime streaming, the buffer we made for |
michael@0 | 59 | // RtspMediaResource is quite small. The small buffer implies the time ranges |
michael@0 | 60 | // we returned are not useful for the MediaDecodeStateMachine. Unlike the |
michael@0 | 61 | // ChannelMediaResource, it has a "cache" that can store the whole streaming |
michael@0 | 62 | // data so the |GetBuffered| function can retrieve useful time ranges. |
michael@0 | 63 | virtual nsresult GetBuffered(mozilla::dom::TimeRanges* aBuffered, |
michael@0 | 64 | int64_t aStartTime) MOZ_FINAL MOZ_OVERRIDE { |
michael@0 | 65 | return NS_OK; |
michael@0 | 66 | } |
michael@0 | 67 | |
michael@0 | 68 | virtual void SetIdle() MOZ_OVERRIDE; |
michael@0 | 69 | virtual void SetActive() MOZ_OVERRIDE; |
michael@0 | 70 | |
michael@0 | 71 | private: |
michael@0 | 72 | // A pointer to RtspMediaResource for calling the Rtsp specific function. |
michael@0 | 73 | // The lifetime of mRtspResource is controlled by MediaDecoder. MediaDecoder |
michael@0 | 74 | // holds the MediaDecoderStateMachine and RtspMediaResource. |
michael@0 | 75 | // And MediaDecoderStateMachine holds this RtspOmxReader. |
michael@0 | 76 | RtspMediaResource* mRtspResource; |
michael@0 | 77 | }; |
michael@0 | 78 | |
michael@0 | 79 | } // namespace mozilla |
michael@0 | 80 | |
michael@0 | 81 | #endif |