Don't call virtual functions in destructors for the writer classes
Have not found any concrete bugs related to these calls yet, but we should avoid
calling virtual functions in destructors, regardless.
Change-Id: I2d47b79d3fb2d29f418619bee83aa147d232a5d4
diff --git a/include/media/stagefright/AACWriter.h b/include/media/stagefright/AACWriter.h
index fa3ab8a..49397ee 100644
--- a/include/media/stagefright/AACWriter.h
+++ b/include/media/stagefright/AACWriter.h
@@ -34,7 +34,7 @@
virtual status_t addSource(const sp<MediaSource> &source);
virtual bool reachedEOS();
virtual status_t start(MetaData *params = NULL);
- virtual status_t stop();
+ virtual status_t stop() { return reset(); }
virtual status_t pause();
protected:
@@ -66,6 +66,7 @@
bool exceedsFileSizeLimit();
bool exceedsFileDurationLimit();
status_t writeAdtsHeader(uint32_t frameLength);
+ status_t reset();
DISALLOW_EVIL_CONSTRUCTORS(AACWriter);
};
diff --git a/include/media/stagefright/AMRWriter.h b/include/media/stagefright/AMRWriter.h
index 62d57b4..392f968 100644
--- a/include/media/stagefright/AMRWriter.h
+++ b/include/media/stagefright/AMRWriter.h
@@ -37,7 +37,7 @@
virtual status_t addSource(const sp<MediaSource> &source);
virtual bool reachedEOS();
virtual status_t start(MetaData *params = NULL);
- virtual status_t stop();
+ virtual status_t stop() { return reset(); }
virtual status_t pause();
protected:
@@ -60,6 +60,7 @@
status_t threadFunc();
bool exceedsFileSizeLimit();
bool exceedsFileDurationLimit();
+ status_t reset();
AMRWriter(const AMRWriter &);
AMRWriter &operator=(const AMRWriter &);
diff --git a/include/media/stagefright/MPEG2TSWriter.h b/include/media/stagefright/MPEG2TSWriter.h
index e4c1c49..a7c9ecf 100644
--- a/include/media/stagefright/MPEG2TSWriter.h
+++ b/include/media/stagefright/MPEG2TSWriter.h
@@ -37,7 +37,7 @@
virtual status_t addSource(const sp<MediaSource> &source);
virtual status_t start(MetaData *param = NULL);
- virtual status_t stop();
+ virtual status_t stop() { return reset(); }
virtual status_t pause();
virtual bool reachedEOS();
virtual status_t dump(int fd, const Vector<String16>& args);
@@ -78,6 +78,7 @@
void writeAccessUnit(int32_t sourceIndex, const sp<ABuffer> &buffer);
ssize_t internalWrite(const void *data, size_t size);
+ status_t reset();
DISALLOW_EVIL_CONSTRUCTORS(MPEG2TSWriter);
};
diff --git a/include/media/stagefright/MPEG4Writer.h b/include/media/stagefright/MPEG4Writer.h
index 77166ed..0409b30 100644
--- a/include/media/stagefright/MPEG4Writer.h
+++ b/include/media/stagefright/MPEG4Writer.h
@@ -37,7 +37,7 @@
virtual status_t addSource(const sp<MediaSource> &source);
virtual status_t start(MetaData *param = NULL);
- virtual status_t stop();
+ virtual status_t stop() { return reset(); }
virtual status_t pause();
virtual bool reachedEOS();
virtual status_t dump(int fd, const Vector<String16>& args);
@@ -184,6 +184,7 @@
void writeLongitude(int degreex10000);
void sendSessionSummary();
void release();
+ status_t reset();
MPEG4Writer(const MPEG4Writer &);
MPEG4Writer &operator=(const MPEG4Writer &);
diff --git a/media/libstagefright/AACWriter.cpp b/media/libstagefright/AACWriter.cpp
index 1673ccd..9cdb463 100644
--- a/media/libstagefright/AACWriter.cpp
+++ b/media/libstagefright/AACWriter.cpp
@@ -60,7 +60,7 @@
AACWriter::~AACWriter() {
if (mStarted) {
- stop();
+ reset();
}
if (mFd != -1) {
@@ -152,7 +152,7 @@
return OK;
}
-status_t AACWriter::stop() {
+status_t AACWriter::reset() {
if (!mStarted) {
return OK;
}
diff --git a/media/libstagefright/AMRWriter.cpp b/media/libstagefright/AMRWriter.cpp
index 6c4e307..59b4ca7 100644
--- a/media/libstagefright/AMRWriter.cpp
+++ b/media/libstagefright/AMRWriter.cpp
@@ -52,7 +52,7 @@
AMRWriter::~AMRWriter() {
if (mStarted) {
- stop();
+ reset();
}
if (mFd != -1) {
@@ -152,7 +152,7 @@
return OK;
}
-status_t AMRWriter::stop() {
+status_t AMRWriter::reset() {
if (!mStarted) {
return OK;
}
diff --git a/media/libstagefright/MPEG2TSWriter.cpp b/media/libstagefright/MPEG2TSWriter.cpp
index 36009ab..0b4ecbe 100644
--- a/media/libstagefright/MPEG2TSWriter.cpp
+++ b/media/libstagefright/MPEG2TSWriter.cpp
@@ -513,7 +513,7 @@
MPEG2TSWriter::~MPEG2TSWriter() {
if (mStarted) {
- stop();
+ reset();
}
mLooper->unregisterHandler(mReflector->id());
@@ -564,7 +564,7 @@
return OK;
}
-status_t MPEG2TSWriter::stop() {
+status_t MPEG2TSWriter::reset() {
CHECK(mStarted);
for (size_t i = 0; i < mSources.size(); ++i) {
diff --git a/media/libstagefright/MPEG4Writer.cpp b/media/libstagefright/MPEG4Writer.cpp
index 06dd875..068660b 100755
--- a/media/libstagefright/MPEG4Writer.cpp
+++ b/media/libstagefright/MPEG4Writer.cpp
@@ -282,7 +282,7 @@
}
MPEG4Writer::~MPEG4Writer() {
- stop();
+ reset();
while (!mTracks.empty()) {
List<Track *>::iterator it = mTracks.begin();
@@ -616,7 +616,7 @@
mStarted = false;
}
-status_t MPEG4Writer::stop() {
+status_t MPEG4Writer::reset() {
if (mInitCheck != OK) {
return OK;
} else {