From 14f7672b5d450ed26a06fd3bb3ce045ea78b11b2 Mon Sep 17 00:00:00 2001 From: Andreas Huber Date: Tue, 15 Jan 2013 09:04:18 -0800 Subject: New HLS implementation supporting independent stream sources, audio-only streams and more. Change-Id: Icfc45a0100243b2f7a14a9e65696be45b67d6495 --- media/libstagefright/httplive/LiveSession.h | 172 ++++++++++++++++++++++++++++ 1 file changed, 172 insertions(+) create mode 100644 media/libstagefright/httplive/LiveSession.h (limited to 'media/libstagefright/httplive/LiveSession.h') diff --git a/media/libstagefright/httplive/LiveSession.h b/media/libstagefright/httplive/LiveSession.h new file mode 100644 index 0000000..b134725 --- /dev/null +++ b/media/libstagefright/httplive/LiveSession.h @@ -0,0 +1,172 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef LIVE_SESSION_H_ + +#define LIVE_SESSION_H_ + +#include + +#include + +namespace android { + +struct ABuffer; +struct AnotherPacketSource; +struct DataSource; +struct HTTPBase; +struct LiveDataSource; +struct M3UParser; +struct PlaylistFetcher; + +struct LiveSession : public AHandler { + enum Flags { + // Don't log any URLs. + kFlagIncognito = 1, + }; + LiveSession( + const sp ¬ify, + uint32_t flags = 0, bool uidValid = false, uid_t uid = 0); + + enum StreamType { + STREAMTYPE_AUDIO = 1, + STREAMTYPE_VIDEO = 2, + STREAMTYPE_SUBTITLES = 4, + }; + status_t dequeueAccessUnit(StreamType stream, sp *accessUnit); + + status_t getStreamFormat(StreamType stream, sp *format); + + void connectAsync( + const char *url, + const KeyedVector *headers = NULL); + + status_t disconnect(); + + // Blocks until seek is complete. + status_t seekTo(int64_t timeUs); + + status_t getDuration(int64_t *durationUs) const; + + bool isSeekable() const; + bool hasDynamicDuration() const; + + enum { + kWhatStreamsChanged, + kWhatError, + kWhatPrepared, + kWhatPreparationFailed, + }; + +protected: + virtual ~LiveSession(); + + virtual void onMessageReceived(const sp &msg); + +private: + friend struct PlaylistFetcher; + + enum { + kWhatConnect = 'conn', + kWhatDisconnect = 'disc', + kWhatSeek = 'seek', + kWhatFetcherNotify = 'notf', + kWhatCheckBandwidth = 'bndw', + kWhatChangeConfiguration2 = 'chC2', + kWhatChangeConfiguration3 = 'chC3', + kWhatFinishDisconnect2 = 'fin2', + }; + + struct BandwidthItem { + size_t mPlaylistIndex; + unsigned long mBandwidth; + }; + + struct FetcherInfo { + sp mFetcher; + int64_t mDurationUs; + bool mIsPrepared; + }; + + sp mNotify; + uint32_t mFlags; + bool mUIDValid; + uid_t mUID; + + bool mInPreparationPhase; + + sp mHTTPDataSource; + KeyedVector mExtraHeaders; + + AString mMasterURL; + + Vector mBandwidthItems; + ssize_t mPrevBandwidthIndex; + + sp mPlaylist; + + KeyedVector mFetcherInfos; + AString mAudioURI, mVideoURI, mSubtitleURI; + uint32_t mStreamMask; + + KeyedVector > mPacketSources; + + int32_t mCheckBandwidthGeneration; + + size_t mContinuationCounter; + sp mContinuation; + + int64_t mLastDequeuedTimeUs; + + bool mReconfigurationInProgress; + uint32_t mDisconnectReplyID; + + sp addFetcher(const char *uri); + + void onConnect(const sp &msg); + status_t onSeek(const sp &msg); + void onFinishDisconnect2(); + + status_t fetchFile( + const char *url, sp *out, + int64_t range_offset = 0, int64_t range_length = -1); + + sp fetchPlaylist( + const char *url, uint8_t *curPlaylistHash, bool *unchanged); + + size_t getBandwidthIndex(); + + static int SortByBandwidth(const BandwidthItem *, const BandwidthItem *); + + void changeConfiguration(int64_t timeUs, size_t bandwidthIndex); + void onChangeConfiguration2(const sp &msg); + void onChangeConfiguration3(const sp &msg); + + void scheduleCheckBandwidthEvent(); + void cancelCheckBandwidthEvent(); + + void onCheckBandwidth(); + + void finishDisconnect(); + + void postPrepared(status_t err); + + DISALLOW_EVIL_CONSTRUCTORS(LiveSession); +}; + +} // namespace android + +#endif // LIVE_SESSION_H_ -- cgit v1.1 From dcb89b3b505522efde173c105a851c412f947178 Mon Sep 17 00:00:00 2001 From: Chong Zhang Date: Tue, 6 Aug 2013 09:44:47 -0700 Subject: MediaPlayer: add listener for raw track data Bug: 10326117 Change-Id: I2c0bdf8adc67b11f8dc633423bee66897548f181 --- media/libstagefright/httplive/LiveSession.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'media/libstagefright/httplive/LiveSession.h') diff --git a/media/libstagefright/httplive/LiveSession.h b/media/libstagefright/httplive/LiveSession.h index b134725..99b480a8 100644 --- a/media/libstagefright/httplive/LiveSession.h +++ b/media/libstagefright/httplive/LiveSession.h @@ -31,6 +31,7 @@ struct HTTPBase; struct LiveDataSource; struct M3UParser; struct PlaylistFetcher; +struct Parcel; struct LiveSession : public AHandler { enum Flags { @@ -60,6 +61,8 @@ struct LiveSession : public AHandler { status_t seekTo(int64_t timeUs); status_t getDuration(int64_t *durationUs) const; + status_t getTrackInfo(Parcel *reply) const; + status_t selectTrack(size_t index, bool select); bool isSeekable() const; bool hasDynamicDuration() const; @@ -85,6 +88,7 @@ private: kWhatSeek = 'seek', kWhatFetcherNotify = 'notf', kWhatCheckBandwidth = 'bndw', + kWhatChangeConfiguration = 'chC0', kWhatChangeConfiguration2 = 'chC2', kWhatChangeConfiguration3 = 'chC3', kWhatFinishDisconnect2 = 'fin2', @@ -130,6 +134,7 @@ private: sp mContinuation; int64_t mLastDequeuedTimeUs; + int64_t mRealTimeBaseUs; bool mReconfigurationInProgress; uint32_t mDisconnectReplyID; @@ -151,7 +156,9 @@ private: static int SortByBandwidth(const BandwidthItem *, const BandwidthItem *); - void changeConfiguration(int64_t timeUs, size_t bandwidthIndex); + void changeConfiguration( + int64_t timeUs, size_t bandwidthIndex, bool pickTrack = false); + void onChangeConfiguration(const sp &msg); void onChangeConfiguration2(const sp &msg); void onChangeConfiguration3(const sp &msg); -- cgit v1.1