blob: 5185f8bb8bd3ecfd550780ca0c571cac2a8dc9bf [file] [log] [blame]
Ajit Khare470d0922013-01-21 01:11:06 -08001/*
2 *Copyright (c) 2013, The Linux Foundation. All rights reserved.
3 *Not a Contribution, Apache license notifications and license are retained
4 *for attribution purposes only.
5 *Copyright (C) 2010 The Android Open Source Project
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19
20#ifndef DASH_PACKET_SOURCE_H_
21
22#define DASH_PACKET_SOURCE_H_
23
24#include <media/stagefright/foundation/ABase.h>
25#include <media/stagefright/MediaSource.h>
26#include <utils/threads.h>
27#include <utils/List.h>
28
29#include "ATSParser.h"
30
31namespace android {
32
33struct ABuffer;
34
35struct DashPacketSource : public MediaSource {
36 DashPacketSource(const sp<MetaData> &meta);
37
38 void setFormat(const sp<MetaData> &meta);
39
40 virtual status_t start(MetaData *params = NULL);
41 virtual status_t stop();
42 virtual sp<MetaData> getFormat();
43
44 virtual status_t read(
45 MediaBuffer **buffer, const ReadOptions *options = NULL);
46
47 bool hasBufferAvailable(status_t *finalResult);
48
49 // Returns the difference between the last and the first queued
50 // presentation timestamps since the last discontinuity (if any).
51 int64_t getBufferedDurationUs(status_t *finalResult);
52
53 status_t nextBufferTime(int64_t *timeUs);
54
55 void queueAccessUnit(const sp<ABuffer> &buffer);
56
57 void queueDiscontinuity(
58 ATSParser::DiscontinuityType type, const sp<AMessage> &extra);
59
60 void signalEOS(status_t result);
61
62 status_t dequeueAccessUnit(sp<ABuffer> *buffer);
63 void updateFormat(const sp<MetaData> &meta);
64 int getQueueSize();
65
66 status_t getStreamInfo(unsigned& streamPID, unsigned& programPID, uint64_t& firstPTS);
67
68 void setStreamInfo(unsigned streamPID, unsigned programPID, uint64_t firstPTS);
69
70 status_t nextBufferIsSync(bool* isSyncFrame);
71
72protected:
73 virtual ~DashPacketSource();
74
75private:
76 Mutex mLock;
77 Condition mCondition;
78
79 bool mIsAudio;
80 sp<MetaData> mFormat;
81 List<sp<ABuffer> > mBuffers;
82 status_t mEOSResult;
83 unsigned mStreamPID;
84 unsigned mProgramPID;
85 uint64_t mFirstPTS;
86
87 bool wasFormatChange(int32_t discontinuityType) const;
88
89 DISALLOW_EVIL_CONSTRUCTORS(DashPacketSource);
90};
91
92
93} // namespace android
94
95#endif // DASH_PACKET_SOURCE_H_