C-ify MediaTrack

Add C-API replacement for MediaTrack in extractor plugins.
Move MediaTrack from libmediaextractor.so to libmedia.so

Bug: 111407253
Test: CTS, manual

Change-Id: I3407e903fe41a2d7b7233538808281fce318c27a
gugelfrei
Marco Nelissen 6 years ago
parent f7f463120a
commit 2a3363ad85

@ -23,6 +23,7 @@ namespace android {
struct MediaTrack;
class MetaDataBase;
class MediaBufferBase;
extern "C" {
@ -34,12 +35,33 @@ struct CDataSource {
void *handle;
};
enum CMediaTrackReadOptions : uint32_t {
SEEK_PREVIOUS_SYNC = 0,
SEEK_NEXT_SYNC = 1,
SEEK_CLOSEST_SYNC = 2,
SEEK_CLOSEST = 3,
SEEK_FRAME_INDEX = 4,
SEEK = 8,
NONBLOCKING = 16
};
struct CMediaTrack {
void *data;
void (*free)(void *data);
status_t (*start)(void *data, MetaDataBase *params);
status_t (*stop)(void *data);
status_t (*getFormat)(void *data, MetaDataBase &format);
status_t (*read)(void *data, MediaBufferBase **buffer, uint32_t options, int64_t seekPosUs);
bool (*supportsNonBlockingRead)(void *data);
};
struct CMediaExtractor {
void *data;
void (*free)(void *data);
size_t (*countTracks)(void *data);
MediaTrack* (*getTrack)(void *data, size_t index);
CMediaTrack* (*getTrack)(void *data, size_t index);
status_t (*getTrackMetaData)(
void *data,
MetaDataBase& meta,

@ -33,6 +33,75 @@ class DataSourceBase;
class MetaDataBase;
struct MediaTrack;
class MediaTrackHelper {
public:
virtual ~MediaTrackHelper() {};
virtual status_t start(MetaDataBase *params = NULL) = 0;
virtual status_t stop() = 0;
virtual status_t getFormat(MetaDataBase& format) = 0;
class ReadOptions {
public:
enum SeekMode : int32_t {
SEEK_PREVIOUS_SYNC,
SEEK_NEXT_SYNC,
SEEK_CLOSEST_SYNC,
SEEK_CLOSEST,
SEEK_FRAME_INDEX,
};
ReadOptions(uint32_t options, int64_t seekPosUs) {
mOptions = options;
mSeekPosUs = seekPosUs;
}
bool getSeekTo(int64_t *time_us, SeekMode *mode) const {
if ((mOptions & CMediaTrackReadOptions::SEEK) == 0) {
return false;
}
*time_us = mSeekPosUs;
*mode = (SeekMode) (mOptions & 7);
return true;
}
bool getNonBlocking() const {
return mOptions & CMediaTrackReadOptions::NONBLOCKING;
}
private:
uint32_t mOptions;
int64_t mSeekPosUs;
};
virtual status_t read(
MediaBufferBase **buffer, const ReadOptions *options = NULL) = 0;
virtual bool supportsNonBlockingRead() { return false; }
};
inline CMediaTrack *wrap(MediaTrackHelper *track) {
CMediaTrack *wrapper = (CMediaTrack*) malloc(sizeof(CMediaTrack));
wrapper->data = track;
wrapper->free = [](void *data) -> void {
delete (MediaTrackHelper*)(data);
};
wrapper->start = [](void *data, MetaDataBase *params) -> status_t {
return ((MediaTrackHelper*)data)->start(params);
};
wrapper->stop = [](void *data) -> status_t {
return ((MediaTrackHelper*)data)->stop();
};
wrapper->getFormat = [](void *data, MetaDataBase &meta) -> status_t {
return ((MediaTrackHelper*)data)->getFormat(meta);
};
wrapper->read = [](void *data, MediaBufferBase **buffer, uint32_t options, int64_t seekPosUs)
-> status_t {
MediaTrackHelper::ReadOptions opts(options, seekPosUs);
return ((MediaTrackHelper*)data)->read(buffer, &opts);
};
wrapper->supportsNonBlockingRead = [](void *data) -> bool {
return ((MediaTrackHelper*)data)->supportsNonBlockingRead();
};
return wrapper;
}
// extractor plugins can derive from this class which looks remarkably
// like MediaExtractor and can be easily wrapped in the required C API
class MediaExtractorPluginHelper
@ -40,7 +109,7 @@ class MediaExtractorPluginHelper
public:
virtual ~MediaExtractorPluginHelper() {}
virtual size_t countTracks() = 0;
virtual MediaTrack *getTrack(size_t index) = 0;
virtual MediaTrackHelper *getTrack(size_t index) = 0;
enum GetTrackMetaDataFlags {
kIncludeExtensiveMetaData = 1
@ -89,8 +158,8 @@ inline CMediaExtractor *wrap(MediaExtractorPluginHelper *extractor) {
wrapper->countTracks = [](void *data) -> size_t {
return ((MediaExtractorPluginHelper*)data)->countTracks();
};
wrapper->getTrack = [](void *data, size_t index) -> MediaTrack* {
return ((MediaExtractorPluginHelper*)data)->getTrack(index);
wrapper->getTrack = [](void *data, size_t index) -> CMediaTrack* {
return wrap(((MediaExtractorPluginHelper*)data)->getTrack(index));
};
wrapper->getTrackMetaData = [](
void *data,

@ -1 +0,0 @@
../../media/libmediaextractor/include/media/MediaTrack.h

@ -0,0 +1,151 @@
/*
* Copyright (C) 2018 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 MEDIA_SOURCE_BASE_H_
#define MEDIA_SOURCE_BASE_H_
#include <sys/types.h>
#include <binder/IMemory.h>
#include <binder/MemoryDealer.h>
#include <media/stagefright/MediaErrors.h>
#include <media/stagefright/MetaData.h>
#include <media/MediaExtractorPluginApi.h>
#include <utils/Log.h>
#include <utils/RefBase.h>
#include <utils/Vector.h>
namespace android {
class MediaBufferBase;
struct CMediaTrack;
class SourceBaseAllocTracker {
public:
SourceBaseAllocTracker() {
ALOGD("sourcebase allocated: %p", this);
}
virtual ~SourceBaseAllocTracker() {
ALOGD("sourcebase freed: %p", this);
}
};
struct MediaTrack
// : public SourceBaseAllocTracker
{
MediaTrack();
// To be called before any other methods on this object, except
// getFormat().
virtual status_t start(MetaDataBase *params = NULL) = 0;
// Any blocking read call returns immediately with a result of NO_INIT.
// It is an error to call any methods other than start after this call
// returns. Any buffers the object may be holding onto at the time of
// the stop() call are released.
// Also, it is imperative that any buffers output by this object and
// held onto by callers be released before a call to stop() !!!
virtual status_t stop() = 0;
// Returns the format of the data output by this media track.
virtual status_t getFormat(MetaDataBase& format) = 0;
// Options that modify read() behaviour. The default is to
// a) not request a seek
// b) not be late, i.e. lateness_us = 0
struct ReadOptions {
enum SeekMode : int32_t {
SEEK_PREVIOUS_SYNC = CMediaTrackReadOptions::SEEK_PREVIOUS_SYNC,
SEEK_NEXT_SYNC = CMediaTrackReadOptions::SEEK_NEXT_SYNC,
SEEK_CLOSEST_SYNC = CMediaTrackReadOptions::SEEK_CLOSEST_SYNC,
SEEK_CLOSEST = CMediaTrackReadOptions::SEEK_CLOSEST,
SEEK_FRAME_INDEX = CMediaTrackReadOptions::SEEK_FRAME_INDEX,
};
ReadOptions();
// Reset everything back to defaults.
void reset();
void setSeekTo(int64_t time_us, SeekMode mode = SEEK_CLOSEST_SYNC);
void clearSeekTo();
bool getSeekTo(int64_t *time_us, SeekMode *mode) const;
void setNonBlocking();
void clearNonBlocking();
bool getNonBlocking() const;
// Used to clear all non-persistent options for multiple buffer reads.
void clearNonPersistent() {
clearSeekTo();
}
private:
enum Options {
kSeekTo_Option = 1,
};
uint32_t mOptions;
int64_t mSeekTimeUs;
SeekMode mSeekMode;
bool mNonBlocking;
} __attribute__((packed)); // sent through Binder
// Returns a new buffer of data. Call blocks until a
// buffer is available, an error is encountered of the end of the stream
// is reached.
// End of stream is signalled by a result of ERROR_END_OF_STREAM.
// A result of INFO_FORMAT_CHANGED indicates that the format of this
// MediaSource has changed mid-stream, the client can continue reading
// but should be prepared for buffers of the new configuration.
virtual status_t read(
MediaBufferBase **buffer, const ReadOptions *options = NULL) = 0;
// Returns true if |read| supports nonblocking option, otherwise false.
// |readMultiple| if supported, always allows the nonblocking option.
virtual bool supportNonblockingRead() {
return false;
}
virtual ~MediaTrack();
private:
MediaTrack(const MediaTrack &);
MediaTrack &operator=(const MediaTrack &);
};
class MediaTrackCUnwrapper : public MediaTrack {
public:
explicit MediaTrackCUnwrapper(CMediaTrack *wrapper);
virtual status_t start(MetaDataBase *params = NULL);
virtual status_t stop();
virtual status_t getFormat(MetaDataBase& format);
virtual status_t read(MediaBufferBase **buffer, const ReadOptions *options = NULL);
virtual bool supportNonblockingRead();
protected:
virtual ~MediaTrackCUnwrapper();
private:
CMediaTrack *wrapper;
};
} // namespace android
#endif // MEDIA_SOURCE_BASE_H_

@ -20,7 +20,6 @@
#include "AACExtractor.h"
#include <media/MediaExtractorPluginApi.h>
#include <media/MediaTrack.h>
#include <media/stagefright/foundation/ABuffer.h>
#include <media/stagefright/foundation/AMessage.h>
#include <media/stagefright/foundation/ADebug.h>
@ -33,7 +32,7 @@
namespace android {
class AACSource : public MediaTrack {
class AACSource : public MediaTrackHelper {
public:
AACSource(
DataSourceHelper *source,
@ -196,7 +195,7 @@ size_t AACExtractor::countTracks() {
return mInitCheck == OK ? 1 : 0;
}
MediaTrack *AACExtractor::getTrack(size_t index) {
MediaTrackHelper *AACExtractor::getTrack(size_t index) {
if (mInitCheck != OK || index != 0) {
return NULL;
}

@ -34,7 +34,7 @@ public:
AACExtractor(DataSourceHelper *source, off64_t offset);
virtual size_t countTracks();
virtual MediaTrack *getTrack(size_t index);
virtual MediaTrackHelper *getTrack(size_t index);
virtual status_t getTrackMetaData(MetaDataBase& meta, size_t index, uint32_t flags);
virtual status_t getMetaData(MetaDataBase& meta);

@ -20,7 +20,6 @@
#include "AMRExtractor.h"
#include <media/MediaTrack.h>
#include <media/stagefright/foundation/ADebug.h>
#include <media/stagefright/MediaBufferGroup.h>
#include <media/stagefright/MediaDefs.h>
@ -30,7 +29,7 @@
namespace android {
class AMRSource : public MediaTrack {
class AMRSource : public MediaTrackHelper {
public:
AMRSource(
DataSourceHelper *source,
@ -208,7 +207,7 @@ size_t AMRExtractor::countTracks() {
return mInitCheck == OK ? 1 : 0;
}
MediaTrack *AMRExtractor::getTrack(size_t index) {
MediaTrackHelper *AMRExtractor::getTrack(size_t index) {
if (mInitCheck != OK || index != 0) {
return NULL;
}

@ -34,7 +34,7 @@ public:
explicit AMRExtractor(DataSourceHelper *source);
virtual size_t countTracks();
virtual MediaTrack *getTrack(size_t index);
virtual MediaTrackHelper *getTrack(size_t index);
virtual status_t getTrackMetaData(MetaDataBase& meta, size_t index, uint32_t flags);
virtual status_t getMetaData(MetaDataBase& meta);

@ -25,13 +25,13 @@
#include "FLAC/stream_decoder.h"
#include <media/MediaExtractorPluginApi.h>
#include <media/MediaTrack.h>
#include <media/VorbisComment.h>
#include <media/stagefright/foundation/ABuffer.h>
#include <media/stagefright/foundation/ADebug.h>
#include <media/stagefright/foundation/base64.h>
#include <media/stagefright/MediaBufferGroup.h>
#include <media/stagefright/MediaDefs.h>
#include <media/stagefright/MediaErrors.h>
#include <media/stagefright/MetaData.h>
#include <media/stagefright/MediaBufferBase.h>
@ -39,7 +39,7 @@ namespace android {
class FLACParser;
class FLACSource : public MediaTrack {
class FLACSource : public MediaTrackHelper {
public:
FLACSource(
@ -812,7 +812,7 @@ size_t FLACExtractor::countTracks()
return mInitCheck == OK ? 1 : 0;
}
MediaTrack *FLACExtractor::getTrack(size_t index)
MediaTrackHelper *FLACExtractor::getTrack(size_t index)
{
if (mInitCheck != OK || index > 0) {
return NULL;

@ -33,7 +33,7 @@ public:
explicit FLACExtractor(DataSourceHelper *source);
virtual size_t countTracks();
virtual MediaTrack *getTrack(size_t index);
virtual MediaTrackHelper *getTrack(size_t index);
virtual status_t getTrackMetaData(MetaDataBase& meta, size_t index, uint32_t flags);
virtual status_t getMetaData(MetaDataBase& meta);

@ -24,8 +24,8 @@
#include <media/stagefright/foundation/ADebug.h>
#include <media/stagefright/MediaBufferGroup.h>
#include <media/stagefright/MediaDefs.h>
#include <media/stagefright/MediaErrors.h>
#include <media/stagefright/MetaData.h>
#include <media/MediaTrack.h>
#include <libsonivox/eas_reverb.h>
namespace android {
@ -33,7 +33,7 @@ namespace android {
// how many Sonivox output buffers to aggregate into one MediaBufferBase
static const int NUM_COMBINE_BUFFERS = 4;
class MidiSource : public MediaTrack {
class MidiSource : public MediaTrackHelper {
public:
MidiSource(
@ -282,7 +282,7 @@ size_t MidiExtractor::countTracks()
return mInitCheck == OK ? 1 : 0;
}
MediaTrack *MidiExtractor::getTrack(size_t index)
MediaTrackHelper *MidiExtractor::getTrack(size_t index)
{
if (mInitCheck != OK || index > 0) {
return NULL;

@ -57,7 +57,7 @@ public:
explicit MidiExtractor(CDataSource *source);
virtual size_t countTracks();
virtual MediaTrack *getTrack(size_t index);
virtual MediaTrackHelper *getTrack(size_t index);
virtual status_t getTrackMetaData(MetaDataBase& meta, size_t index, uint32_t flags);
virtual status_t getMetaData(MetaDataBase& meta);

@ -23,7 +23,6 @@
#include <media/DataSourceBase.h>
#include <media/ExtractorUtils.h>
#include <media/MediaTrack.h>
#include <media/stagefright/foundation/ADebug.h>
#include <media/stagefright/foundation/AUtils.h>
#include <media/stagefright/foundation/ABuffer.h>
@ -124,7 +123,7 @@ private:
BlockIterator &operator=(const BlockIterator &);
};
struct MatroskaSource : public MediaTrack {
struct MatroskaSource : public MediaTrackHelper {
MatroskaSource(MatroskaExtractor *extractor, size_t index);
virtual status_t start(MetaDataBase *params);
@ -1002,7 +1001,7 @@ size_t MatroskaExtractor::countTracks() {
return mTracks.size();
}
MediaTrack *MatroskaExtractor::getTrack(size_t index) {
MediaTrackHelper *MatroskaExtractor::getTrack(size_t index) {
if (index >= mTracks.size()) {
return NULL;
}

@ -40,7 +40,7 @@ struct MatroskaExtractor : public MediaExtractorPluginHelper {
virtual size_t countTracks();
virtual MediaTrack *getTrack(size_t index);
virtual MediaTrackHelper *getTrack(size_t index);
virtual status_t getTrackMetaData(MetaDataBase& meta, size_t index, uint32_t flags);

@ -24,7 +24,6 @@
#include "VBRISeeker.h"
#include "XINGSeeker.h"
#include <media/MediaTrack.h>
#include <media/stagefright/foundation/ADebug.h>
#include <media/stagefright/foundation/AMessage.h>
#include <media/stagefright/foundation/avc_utils.h>
@ -208,7 +207,7 @@ static bool Resync(
return valid;
}
class MP3Source : public MediaTrack {
class MP3Source : public MediaTrackHelper {
public:
MP3Source(
MetaDataBase &meta, DataSourceHelper *source,
@ -411,7 +410,7 @@ size_t MP3Extractor::countTracks() {
return mInitCheck != OK ? 0 : 1;
}
MediaTrack *MP3Extractor::getTrack(size_t index) {
MediaTrackHelper *MP3Extractor::getTrack(size_t index) {
if (mInitCheck != OK || index != 0) {
return NULL;
}

@ -38,7 +38,7 @@ public:
~MP3Extractor();
virtual size_t countTracks();
virtual MediaTrack *getTrack(size_t index);
virtual MediaTrackHelper *getTrack(size_t index);
virtual status_t getTrackMetaData(MetaDataBase& meta, size_t index, uint32_t flags);
virtual status_t getMetaData(MetaDataBase& meta);

@ -34,7 +34,6 @@
#include <media/DataSourceBase.h>
#include <media/ExtractorUtils.h>
#include <media/MediaTrack.h>
#include <media/stagefright/foundation/ABitReader.h>
#include <media/stagefright/foundation/ABuffer.h>
#include <media/stagefright/foundation/ADebug.h>
@ -68,7 +67,7 @@ enum {
kMaxAtomSize = 64 * 1024 * 1024,
};
class MPEG4Source : public MediaTrack {
class MPEG4Source : public MediaTrackHelper {
static const size_t kMaxPcmFrameSize = 8192;
public:
// Caller retains ownership of both "dataSource" and "sampleTable".
@ -3616,7 +3615,7 @@ void MPEG4Extractor::parseID3v2MetaData(off64_t offset) {
}
}
MediaTrack *MPEG4Extractor::getTrack(size_t index) {
MediaTrackHelper *MPEG4Extractor::getTrack(size_t index) {
status_t err;
if ((err = readMetaData()) != OK) {
return NULL;

@ -58,7 +58,7 @@ public:
explicit MPEG4Extractor(DataSourceHelper *source, const char *mime = NULL);
virtual size_t countTracks();
virtual MediaTrack *getTrack(size_t index);
virtual MediaTrackHelper *getTrack(size_t index);
virtual status_t getTrackMetaData(MetaDataBase& meta, size_t index, uint32_t flags);
virtual status_t getMetaData(MetaDataBase& meta);

@ -24,7 +24,6 @@
#include "mpeg2ts/ESQueue.h"
#include <media/DataSourceBase.h>
#include <media/MediaTrack.h>
#include <media/stagefright/foundation/ABitReader.h>
#include <media/stagefright/foundation/ABuffer.h>
#include <media/stagefright/foundation/ADebug.h>
@ -40,7 +39,7 @@
namespace android {
struct MPEG2PSExtractor::Track : public MediaTrack, public RefBase {
struct MPEG2PSExtractor::Track : public MediaTrackHelper, public RefBase {
Track(MPEG2PSExtractor *extractor,
unsigned stream_id, unsigned stream_type);
@ -72,7 +71,7 @@ private:
DISALLOW_EVIL_CONSTRUCTORS(Track);
};
struct MPEG2PSExtractor::WrappedTrack : public MediaTrack {
struct MPEG2PSExtractor::WrappedTrack : public MediaTrackHelper {
WrappedTrack(MPEG2PSExtractor *extractor, const sp<Track> &track);
virtual status_t start(MetaDataBase *params);
@ -127,7 +126,7 @@ size_t MPEG2PSExtractor::countTracks() {
return mTracks.size();
}
MediaTrack *MPEG2PSExtractor::getTrack(size_t index) {
MediaTrackHelper *MPEG2PSExtractor::getTrack(size_t index) {
if (index >= mTracks.size()) {
return NULL;
}
@ -681,7 +680,7 @@ status_t MPEG2PSExtractor::Track::read(
}
}
return mSource->read(buffer, options);
return mSource->read(buffer, (MediaSource::ReadOptions*)options);
}
status_t MPEG2PSExtractor::Track::appendPESData(

@ -36,7 +36,7 @@ struct MPEG2PSExtractor : public MediaExtractorPluginHelper {
explicit MPEG2PSExtractor(DataSourceHelper *source);
virtual size_t countTracks();
virtual MediaTrack *getTrack(size_t index);
virtual MediaTrackHelper *getTrack(size_t index);
virtual status_t getTrackMetaData(MetaDataBase& meta, size_t index, uint32_t flags);
virtual status_t getMetaData(MetaDataBase& meta);

@ -26,7 +26,6 @@
#include <media/DataSourceBase.h>
#include <media/IStreamSource.h>
#include <media/MediaTrack.h>
#include <media/stagefright/foundation/ABuffer.h>
#include <media/stagefright/foundation/ADebug.h>
#include <media/stagefright/foundation/ALooper.h>
@ -51,7 +50,7 @@ static const size_t kTSPacketSize = 188;
static const int kMaxDurationReadSize = 250000LL;
static const int kMaxDurationRetry = 6;
struct MPEG2TSSource : public MediaTrack {
struct MPEG2TSSource : public MediaTrackHelper {
MPEG2TSSource(
MPEG2TSExtractor *extractor,
const sp<AnotherPacketSource> &impl,
@ -110,7 +109,7 @@ status_t MPEG2TSSource::read(
ReadOptions::SeekMode seekMode;
if (mDoesSeek && options && options->getSeekTo(&seekTimeUs, &seekMode)) {
// seek is needed
status_t err = mExtractor->seek(seekTimeUs, seekMode);
status_t err = mExtractor->seek(seekTimeUs, (ReadOptions::SeekMode)seekMode);
if (err != OK) {
return err;
}
@ -120,7 +119,7 @@ status_t MPEG2TSSource::read(
return ERROR_END_OF_STREAM;
}
return mImpl->read(out, options);
return mImpl->read(out, (MediaSource::ReadOptions*) options);
}
////////////////////////////////////////////////////////////////////////////////
@ -141,7 +140,7 @@ size_t MPEG2TSExtractor::countTracks() {
return mSourceImpls.size();
}
MediaTrack *MPEG2TSExtractor::getTrack(size_t index) {
MediaTrackHelper *MPEG2TSExtractor::getTrack(size_t index) {
if (index >= mSourceImpls.size()) {
return NULL;
}
@ -483,7 +482,7 @@ uint32_t MPEG2TSExtractor::flags() const {
}
status_t MPEG2TSExtractor::seek(int64_t seekTimeUs,
const MediaTrack::ReadOptions::SeekMode &seekMode) {
const MediaTrackHelper::ReadOptions::SeekMode &seekMode) {
if (mSeekSyncPoints == NULL || mSeekSyncPoints->isEmpty()) {
ALOGW("No sync point to seek to.");
// ... and therefore we have nothing useful to do here.
@ -504,18 +503,18 @@ status_t MPEG2TSExtractor::seek(int64_t seekTimeUs,
}
switch (seekMode) {
case MediaTrack::ReadOptions::SEEK_NEXT_SYNC:
case MediaTrackHelper::ReadOptions::SEEK_NEXT_SYNC:
if (index == mSeekSyncPoints->size()) {
ALOGW("Next sync not found; starting from the latest sync.");
--index;
}
break;
case MediaTrack::ReadOptions::SEEK_CLOSEST_SYNC:
case MediaTrack::ReadOptions::SEEK_CLOSEST:
case MediaTrackHelper::ReadOptions::SEEK_CLOSEST_SYNC:
case MediaTrackHelper::ReadOptions::SEEK_CLOSEST:
ALOGW("seekMode not supported: %d; falling back to PREVIOUS_SYNC",
seekMode);
FALLTHROUGH_INTENDED;
case MediaTrack::ReadOptions::SEEK_PREVIOUS_SYNC:
case MediaTrackHelper::ReadOptions::SEEK_PREVIOUS_SYNC:
if (index == 0) {
ALOGW("Previous sync not found; starting from the earliest "
"sync.");

@ -22,7 +22,6 @@
#include <media/stagefright/foundation/ABase.h>
#include <media/MediaExtractorPluginApi.h>
#include <media/MediaExtractorPluginHelper.h>
#include <media/MediaTrack.h>
#include <media/stagefright/MetaDataBase.h>
#include <utils/threads.h>
#include <utils/KeyedVector.h>
@ -43,7 +42,7 @@ struct MPEG2TSExtractor : public MediaExtractorPluginHelper {
explicit MPEG2TSExtractor(DataSourceHelper *source);
virtual size_t countTracks();
virtual MediaTrack *getTrack(size_t index);
virtual MediaTrackHelper *getTrack(size_t index);
virtual status_t getTrackMetaData(MetaDataBase &meta, size_t index, uint32_t flags);
virtual status_t getMetaData(MetaDataBase& meta);
@ -91,7 +90,7 @@ private:
// the data has syntax error during parsing, etc.
status_t feedMore(bool isInit = false);
status_t seek(int64_t seekTimeUs,
const MediaSource::ReadOptions::SeekMode& seekMode);
const MediaTrackHelper::ReadOptions::SeekMode& seekMode);
status_t queueDiscontinuityForSeek(int64_t actualSeekTimeUs);
status_t seekBeyond(int64_t seekTimeUs);

@ -21,9 +21,9 @@
#include "OggExtractor.h"
#include <cutils/properties.h>
#include <utils/Vector.h>
#include <media/DataSourceBase.h>
#include <media/ExtractorUtils.h>
#include <media/MediaTrack.h>
#include <media/VorbisComment.h>
#include <media/stagefright/foundation/ABuffer.h>
#include <media/stagefright/foundation/ADebug.h>
@ -47,7 +47,7 @@ extern "C" {
namespace android {
struct OggSource : public MediaTrack {
struct OggSource : public MediaTrackHelper {
explicit OggSource(OggExtractor *extractor);
virtual status_t getFormat(MetaDataBase &);
@ -1227,7 +1227,7 @@ size_t OggExtractor::countTracks() {
return mInitCheck != OK ? 0 : 1;
}
MediaTrack *OggExtractor::getTrack(size_t index) {
MediaTrackHelper *OggExtractor::getTrack(size_t index) {
if (index >= 1) {
return NULL;
}

@ -34,7 +34,7 @@ struct OggExtractor : public MediaExtractorPluginHelper {
explicit OggExtractor(DataSourceHelper *source);
virtual size_t countTracks();
virtual MediaTrack *getTrack(size_t index);
virtual MediaTrackHelper *getTrack(size_t index);
virtual status_t getTrackMetaData(MetaDataBase& meta, size_t index, uint32_t flags);
virtual status_t getMetaData(MetaDataBase& meta);

@ -22,7 +22,6 @@
#include <audio_utils/primitives.h>
#include <media/DataSourceBase.h>
#include <media/MediaTrack.h>
#include <media/stagefright/foundation/ADebug.h>
#include <media/stagefright/MediaBufferGroup.h>
#include <media/stagefright/MediaDefs.h>
@ -55,7 +54,7 @@ static uint16_t U16_LE_AT(const uint8_t *ptr) {
return ptr[1] << 8 | ptr[0];
}
struct WAVSource : public MediaTrack {
struct WAVSource : public MediaTrackHelper {
WAVSource(
DataSourceHelper *dataSource,
MetaDataBase &meta,
@ -118,7 +117,7 @@ size_t WAVExtractor::countTracks() {
return mInitCheck == OK ? 1 : 0;
}
MediaTrack *WAVExtractor::getTrack(size_t index) {
MediaTrackHelper *WAVExtractor::getTrack(size_t index) {
if (mInitCheck != OK || index > 0) {
return NULL;
}

@ -34,7 +34,7 @@ public:
explicit WAVExtractor(DataSourceHelper *source);
virtual size_t countTracks();
virtual MediaTrack *getTrack(size_t index);
virtual MediaTrackHelper *getTrack(size_t index);
virtual status_t getTrackMetaData(MetaDataBase& meta, size_t index, uint32_t flags);
virtual status_t getMetaData(MetaDataBase& meta);

@ -176,6 +176,7 @@ cc_library {
"IResourceManagerClient.cpp",
"IResourceManagerService.cpp",
"IStreamSource.cpp",
"MediaTrack.cpp",
"MediaUtils.cpp",
"Metadata.cpp",
"mediarecorder.cpp",
@ -266,18 +267,13 @@ cc_library {
},
}
cc_library {
cc_library_static {
name: "libmedia_player2_util",
srcs: [
"BufferingSettings.cpp",
"DataSourceDesc.cpp",
"IDataSource.cpp",
"IMediaExtractor.cpp",
"IMediaExtractorService.cpp",
"IMediaSource.cpp",
"MediaCodecBuffer.cpp",
"MediaUtils.cpp",
"Metadata.cpp",
"NdkWrapper.cpp",
],

@ -14,6 +14,8 @@
* limitations under the License.
*/
#include <mutex>
#include <media/MediaTrack.h>
namespace android {
@ -65,4 +67,48 @@ bool MediaTrack::ReadOptions::getSeekTo(
return (mOptions & kSeekTo_Option) != 0;
}
MediaTrackCUnwrapper::MediaTrackCUnwrapper(CMediaTrack *cmediatrack) {
wrapper = cmediatrack;
}
MediaTrackCUnwrapper::~MediaTrackCUnwrapper() {
wrapper->free(wrapper->data);
free(wrapper);
}
status_t MediaTrackCUnwrapper::start(MetaDataBase *params) {
return wrapper->start(wrapper->data, params);
}
status_t MediaTrackCUnwrapper::stop() {
return wrapper->stop(wrapper->data);
}
status_t MediaTrackCUnwrapper::getFormat(MetaDataBase& format) {
return wrapper->getFormat(wrapper->data, format);
}
status_t MediaTrackCUnwrapper::read(MediaBufferBase **buffer, const ReadOptions *options) {
uint32_t opts = 0;
if (options->getNonBlocking()) {
opts |= CMediaTrackReadOptions::NONBLOCKING;
}
int64_t seekPosition = 0;
MediaTrack::ReadOptions::SeekMode seekMode;
if (options->getSeekTo(&seekPosition, &seekMode)) {
opts |= SEEK;
opts |= (uint32_t) seekMode;
}
return wrapper->read(wrapper->data, buffer, opts, seekPosition);
}
bool MediaTrackCUnwrapper::supportNonblockingRead() {
return wrapper->supportsNonBlockingRead(wrapper->data);
}
} // namespace android

@ -28,7 +28,6 @@ cc_library {
"MediaBufferBase.cpp",
"MediaBufferGroup.cpp",
"MediaSource.cpp",
"MediaTrack.cpp",
"MetaData.cpp",
"MetaDataBase.cpp",
"VorbisComment.cpp",

@ -1,131 +0,0 @@
/*
* Copyright (C) 2018 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 MEDIA_SOURCE_BASE_H_
#define MEDIA_SOURCE_BASE_H_
#include <sys/types.h>
#include <binder/IMemory.h>
#include <binder/MemoryDealer.h>
#include <media/stagefright/MediaErrors.h>
#include <media/stagefright/MetaData.h>
#include <utils/Log.h>
#include <utils/RefBase.h>
#include <utils/Vector.h>
namespace android {
class MediaBufferBase;
class SourceBaseAllocTracker {
public:
SourceBaseAllocTracker() {
ALOGD("sourcebase allocated: %p", this);
}
virtual ~SourceBaseAllocTracker() {
ALOGD("sourcebase freed: %p", this);
}
};
struct MediaTrack
// : public SourceBaseAllocTracker
{
MediaTrack();
// To be called before any other methods on this object, except
// getFormat().
virtual status_t start(MetaDataBase *params = NULL) = 0;
// Any blocking read call returns immediately with a result of NO_INIT.
// It is an error to call any methods other than start after this call
// returns. Any buffers the object may be holding onto at the time of
// the stop() call are released.
// Also, it is imperative that any buffers output by this object and
// held onto by callers be released before a call to stop() !!!
virtual status_t stop() = 0;
// Returns the format of the data output by this media track.
virtual status_t getFormat(MetaDataBase& format) = 0;
// Options that modify read() behaviour. The default is to
// a) not request a seek
// b) not be late, i.e. lateness_us = 0
struct ReadOptions {
enum SeekMode : int32_t {
SEEK_PREVIOUS_SYNC,
SEEK_NEXT_SYNC,
SEEK_CLOSEST_SYNC,
SEEK_CLOSEST,
SEEK_FRAME_INDEX,
};
ReadOptions();
// Reset everything back to defaults.
void reset();
void setSeekTo(int64_t time_us, SeekMode mode = SEEK_CLOSEST_SYNC);
void clearSeekTo();
bool getSeekTo(int64_t *time_us, SeekMode *mode) const;
void setNonBlocking();
void clearNonBlocking();
bool getNonBlocking() const;
// Used to clear all non-persistent options for multiple buffer reads.
void clearNonPersistent() {
clearSeekTo();
}
private:
enum Options {
kSeekTo_Option = 1,
};
uint32_t mOptions;
int64_t mSeekTimeUs;
SeekMode mSeekMode;
bool mNonBlocking;
} __attribute__((packed)); // sent through Binder
// Returns a new buffer of data. Call blocks until a
// buffer is available, an error is encountered of the end of the stream
// is reached.
// End of stream is signalled by a result of ERROR_END_OF_STREAM.
// A result of INFO_FORMAT_CHANGED indicates that the format of this
// MediaSource has changed mid-stream, the client can continue reading
// but should be prepared for buffers of the new configuration.
virtual status_t read(
MediaBufferBase **buffer, const ReadOptions *options = NULL) = 0;
// Returns true if |read| supports nonblocking option, otherwise false.
// |readMultiple| if supported, always allows the nonblocking option.
virtual bool supportNonblockingRead() {
return false;
}
virtual ~MediaTrack();
private:
MediaTrack(const MediaTrack &);
MediaTrack &operator=(const MediaTrack &);
};
} // namespace android
#endif // MEDIA_SOURCE_BASE_H_

@ -4,7 +4,7 @@ cc_library_headers {
export_include_dirs: ["include"],
}
cc_library {
cc_library_static {
name: "libmediaplayer2",
srcs: [
@ -20,7 +20,6 @@ cc_library {
"libgui",
"liblog",
"libmedia_omx",
"libmedia_player2_util",
"libmediaextractor",
"libstagefright_foundation",
"libui",
@ -35,7 +34,6 @@ cc_library {
"libnativewindow",
"libpowermanager",
"libstagefright_httplive",
"libstagefright_player2",
],
export_shared_lib_headers: [
@ -55,8 +53,10 @@ cc_library {
static_libs: [
"libmedia_helper",
"libmediaplayer2-protos",
"libmedia_player2_util",
"libprotobuf-cpp-lite",
"libstagefright_nuplayer2",
"libstagefright_player2",
"libstagefright_rtsp",
"libstagefright_timedtext2",
],

@ -230,7 +230,7 @@ cc_library_shared {
},
}
cc_library {
cc_library_static {
name: "libstagefright_player2",
srcs: [
@ -259,7 +259,6 @@ cc_library {
"libcutils",
"libgui",
"liblog",
"libmedia_player2_util",
"libaudioclient",
"libmediaextractor",
"libmediametrics",
@ -274,16 +273,13 @@ cc_library {
static_libs: [
"libstagefright_esds",
"libmedia_player2_util",
],
header_libs:[
"media_plugin_headers",
],
export_shared_lib_headers: [
"libmedia_player2_util",
],
export_include_dirs: [
"include",
],

@ -22,6 +22,7 @@
#include <media/stagefright/foundation/ADebug.h>
#include <media/stagefright/MediaExtractor.h>
#include <media/stagefright/MetaData.h>
#include <media/MediaTrack.h>
namespace android {
@ -54,7 +55,7 @@ size_t MediaExtractorCUnwrapper::countTracks() {
}
MediaTrack *MediaExtractorCUnwrapper::getTrack(size_t index) {
return wrapper->getTrack(wrapper->data, index);
return new MediaTrackCUnwrapper(wrapper->getTrack(wrapper->data, index));
}
status_t MediaExtractorCUnwrapper::getTrackMetaData(

@ -104,7 +104,6 @@ private:
CMediaExtractor *wrapper;
};
} // namespace android
#endif // MEDIA_EXTRACTOR_H_

Loading…
Cancel
Save