1/*
2 * Copyright 2012, The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *     http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef _ANDROID_MEDIA_MEDIAEXTRACTOR_H_
18#define _ANDROID_MEDIA_MEDIAEXTRACTOR_H_
19
20#include <media/stagefright/foundation/ABase.h>
21#include <media/stagefright/MediaSource.h>
22#include <media/stagefright/DataSource.h>
23#include <utils/Errors.h>
24#include <utils/KeyedVector.h>
25#include <utils/RefBase.h>
26#include <utils/String8.h>
27
28#include "jni.h"
29
30namespace android {
31namespace media {
32class ICas;
33};
34using namespace media;
35
36struct IMediaHTTPService;
37class MetaData;
38struct NuMediaExtractor;
39
40struct JMediaExtractor : public RefBase {
41    JMediaExtractor(JNIEnv *env, jobject thiz);
42
43    status_t setDataSource(
44            const sp<IMediaHTTPService> &httpService,
45            const char *path,
46            const KeyedVector<String8, String8> *headers);
47
48    status_t setDataSource(int fd, off64_t offset, off64_t size);
49    status_t setDataSource(const sp<DataSource> &source);
50
51    status_t setMediaCas(const sp<ICas> &cas);
52
53    size_t countTracks() const;
54    status_t getTrackFormat(size_t index, jobject *format) const;
55
56    status_t getFileFormat(jobject *format) const;
57
58    status_t selectTrack(size_t index);
59    status_t unselectTrack(size_t index);
60
61    status_t seekTo(int64_t timeUs, MediaSource::ReadOptions::SeekMode mode);
62
63    status_t advance();
64    status_t readSampleData(jobject byteBuf, size_t offset, size_t *sampleSize);
65    status_t getSampleTrackIndex(size_t *trackIndex);
66    status_t getSampleTime(int64_t *sampleTimeUs);
67    status_t getSampleFlags(uint32_t *sampleFlags);
68    status_t getSampleMeta(sp<MetaData> *sampleMeta);
69    status_t getMetrics(Parcel *reply) const;
70
71    bool getCachedDuration(int64_t *durationUs, bool *eos) const;
72
73protected:
74    virtual ~JMediaExtractor();
75
76private:
77    jclass mClass;
78    jweak mObject;
79    sp<NuMediaExtractor> mImpl;
80
81    DISALLOW_EVIL_CONSTRUCTORS(JMediaExtractor);
82};
83
84}  // namespace android
85
86#endif  // _ANDROID_MEDIA_MEDIAEXTRACTOR_H_
87