Explicitly use AnotherPacketSource where possible
Instead of using MediaSource and casting to AnotherPacketSource.
Bug: 67908544
Test: build
Change-Id: I14f3ff755e74b11e858941662d7965607b8a7976
diff --git a/media/extractors/mpeg2/MPEG2TSExtractor.cpp b/media/extractors/mpeg2/MPEG2TSExtractor.cpp
index fef4d30..5beaeda 100644
--- a/media/extractors/mpeg2/MPEG2TSExtractor.cpp
+++ b/media/extractors/mpeg2/MPEG2TSExtractor.cpp
@@ -202,9 +202,7 @@
break;
}
if (!haveVideo) {
- sp<AnotherPacketSource> impl =
- (AnotherPacketSource *)mParser->getSource(
- ATSParser::VIDEO).get();
+ sp<AnotherPacketSource> impl = mParser->getSource(ATSParser::VIDEO);
if (impl != NULL) {
sp<MetaData> format = impl->getFormat();
@@ -220,9 +218,7 @@
}
if (!haveAudio) {
- sp<AnotherPacketSource> impl =
- (AnotherPacketSource *)mParser->getSource(
- ATSParser::AUDIO).get();
+ sp<AnotherPacketSource> impl = mParser->getSource(ATSParser::AUDIO);
if (impl != NULL) {
sp<MetaData> format = impl->getFormat();
@@ -261,10 +257,8 @@
off64_t size;
if (mDataSource->getSize(&size) == OK && (haveAudio || haveVideo)) {
sp<AnotherPacketSource> impl = haveVideo
- ? (AnotherPacketSource *)mParser->getSource(
- ATSParser::VIDEO).get()
- : (AnotherPacketSource *)mParser->getSource(
- ATSParser::AUDIO).get();
+ ? mParser->getSource(ATSParser::VIDEO)
+ : mParser->getSource(ATSParser::AUDIO);
size_t prevSyncSize = 1;
int64_t durationUs = -1;
List<int64_t> durations;
@@ -420,8 +414,7 @@
ev.reset();
int64_t firstTimeUs;
- sp<AnotherPacketSource> src =
- (AnotherPacketSource *)mParser->getSource(type).get();
+ sp<AnotherPacketSource> src = mParser->getSource(type);
if (src == NULL || src->nextBufferTime(&firstTimeUs) != OK) {
continue;
}
@@ -449,7 +442,7 @@
if (!allDurationsFound) {
allDurationsFound = true;
for (auto t: {ATSParser::VIDEO, ATSParser::AUDIO}) {
- sp<AnotherPacketSource> src = (AnotherPacketSource *)mParser->getSource(t).get();
+ sp<AnotherPacketSource> src = mParser->getSource(t);
if (src == NULL) {
continue;
}
diff --git a/media/libstagefright/mpeg2ts/ATSParser.cpp b/media/libstagefright/mpeg2ts/ATSParser.cpp
index 464ee90..e9c5458 100644
--- a/media/libstagefright/mpeg2ts/ATSParser.cpp
+++ b/media/libstagefright/mpeg2ts/ATSParser.cpp
@@ -77,7 +77,7 @@
void signalEOS(status_t finalResult);
- sp<MediaSource> getSource(SourceType type);
+ sp<AnotherPacketSource> getSource(SourceType type);
bool hasSource(SourceType type) const;
int64_t convertPTSToTimestamp(uint64_t PTS);
@@ -170,7 +170,7 @@
void signalEOS(status_t finalResult);
SourceType getSourceType();
- sp<MediaSource> getSource(SourceType type);
+ sp<AnotherPacketSource> getSource(SourceType type);
bool isAudio() const;
bool isVideo() const;
@@ -274,7 +274,7 @@
ATSParser::SyncEvent::SyncEvent(off64_t offset)
: mHasReturnedData(false), mOffset(offset), mTimeUs(0) {}
-void ATSParser::SyncEvent::init(off64_t offset, const sp<MediaSource> &source,
+void ATSParser::SyncEvent::init(off64_t offset, const sp<AnotherPacketSource> &source,
int64_t timeUs, SourceType type) {
mHasReturnedData = true;
mOffset = offset;
@@ -641,9 +641,9 @@
return mLastRecoveredPTS;
}
-sp<MediaSource> ATSParser::Program::getSource(SourceType type) {
+sp<AnotherPacketSource> ATSParser::Program::getSource(SourceType type) {
for (size_t i = 0; i < mStreams.size(); ++i) {
- sp<MediaSource> source = mStreams.editValueAt(i)->getSource(type);
+ sp<AnotherPacketSource> source = mStreams.editValueAt(i)->getSource(type);
if (source != NULL) {
return source;
}
@@ -1607,7 +1607,7 @@
return NUM_SOURCE_TYPES;
}
-sp<MediaSource> ATSParser::Stream::getSource(SourceType type) {
+sp<AnotherPacketSource> ATSParser::Stream::getSource(SourceType type) {
switch (type) {
case VIDEO:
{
@@ -2042,11 +2042,11 @@
return err;
}
-sp<MediaSource> ATSParser::getSource(SourceType type) {
- sp<MediaSource> firstSourceFound;
+sp<AnotherPacketSource> ATSParser::getSource(SourceType type) {
+ sp<AnotherPacketSource> firstSourceFound;
for (size_t i = 0; i < mPrograms.size(); ++i) {
const sp<Program> &program = mPrograms.editItemAt(i);
- sp<MediaSource> source = program->getSource(type);
+ sp<AnotherPacketSource> source = program->getSource(type);
if (source == NULL) {
continue;
}
diff --git a/media/libstagefright/mpeg2ts/ATSParser.h b/media/libstagefright/mpeg2ts/ATSParser.h
index 6079afc..45ca06b 100644
--- a/media/libstagefright/mpeg2ts/ATSParser.h
+++ b/media/libstagefright/mpeg2ts/ATSParser.h
@@ -81,13 +81,13 @@
struct SyncEvent {
explicit SyncEvent(off64_t offset);
- void init(off64_t offset, const sp<MediaSource> &source,
+ void init(off64_t offset, const sp<AnotherPacketSource> &source,
int64_t timeUs, SourceType type);
bool hasReturnedData() const { return mHasReturnedData; }
void reset();
off64_t getOffset() const { return mOffset; }
- const sp<MediaSource> &getMediaSource() const { return mMediaSource; }
+ const sp<AnotherPacketSource> &getMediaSource() const { return mMediaSource; }
int64_t getTimeUs() const { return mTimeUs; }
SourceType getType() const { return mType; }
@@ -100,7 +100,7 @@
*/
off64_t mOffset;
/* The media source object for this event. */
- sp<MediaSource> mMediaSource;
+ sp<AnotherPacketSource> mMediaSource;
/* The timestamp of the sync frame. */
int64_t mTimeUs;
SourceType mType;
@@ -126,7 +126,7 @@
void signalEOS(status_t finalResult);
- sp<MediaSource> getSource(SourceType type);
+ sp<AnotherPacketSource> getSource(SourceType type);
bool hasSource(SourceType type) const;
bool PTSTimeDeltaEstablished();