diff options
Diffstat (limited to 'cmds')
-rw-r--r-- | cmds/stagefright/SineSource.cpp | 4 | ||||
-rw-r--r-- | cmds/stagefright/record.cpp | 51 | ||||
-rw-r--r-- | cmds/stagefright/stagefright.cpp | 57 |
3 files changed, 75 insertions, 37 deletions
diff --git a/cmds/stagefright/SineSource.cpp b/cmds/stagefright/SineSource.cpp index e5a6ccb..e272a65 100644 --- a/cmds/stagefright/SineSource.cpp +++ b/cmds/stagefright/SineSource.cpp @@ -86,8 +86,8 @@ status_t SineSource::read( x += k; } - buffer->meta_data()->setInt32(kKeyTimeUnits, mPhase); - buffer->meta_data()->setInt32(kKeyTimeScale, mSampleRate); + buffer->meta_data()->setInt64( + kKeyTime, ((int64_t)mPhase * 1000000) / mSampleRate); mPhase += numFramesPerBuffer; diff --git a/cmds/stagefright/record.cpp b/cmds/stagefright/record.cpp index 323d448..a31a5c0 100644 --- a/cmds/stagefright/record.cpp +++ b/cmds/stagefright/record.cpp @@ -19,21 +19,23 @@ #include <binder/ProcessState.h> #include <media/stagefright/AudioPlayer.h> #include <media/stagefright/CameraSource.h> +#include <media/stagefright/FileSource.h> #include <media/stagefright/MediaBufferGroup.h> #include <media/stagefright/MediaDebug.h> #include <media/stagefright/MediaDefs.h> #include <media/stagefright/MetaData.h> -#include <media/stagefright/MPEG4Extractor.h> +#include <media/stagefright/MediaExtractor.h> #include <media/stagefright/MPEG4Writer.h> -#include <media/stagefright/MmapSource.h> #include <media/stagefright/OMXClient.h> #include <media/stagefright/OMXCodec.h> #include <media/MediaPlayerInterface.h> using namespace android; -#if 0 +#if 1 class DummySource : public MediaSource { + static const int32_t kFramerate = 24; // fps + public: DummySource(int width, int height) : mWidth(width), @@ -52,6 +54,7 @@ public: } virtual status_t start(MetaData *params) { + mNumFramesOutput = 0; return OK; } @@ -61,6 +64,12 @@ public: virtual status_t read( MediaBuffer **buffer, const MediaSource::ReadOptions *options) { + if (mNumFramesOutput == kFramerate * 10) { + // Stop returning data after 10 secs. + return ERROR_END_OF_STREAM; + } + + // printf("DummySource::read\n"); status_t err = mGroup.acquire_buffer(buffer); if (err != OK) { return err; @@ -69,7 +78,13 @@ public: char x = (char)((double)rand() / RAND_MAX * 255); memset((*buffer)->data(), x, mSize); (*buffer)->set_range(0, mSize); + (*buffer)->meta_data()->clear(); + (*buffer)->meta_data()->setInt64( + kKeyTime, (mNumFramesOutput * 1000000) / kFramerate); + ++mNumFramesOutput; + // printf("DummySource::read - returning buffer\n"); + // LOGI("DummySource::read - returning buffer"); return OK; } @@ -80,6 +95,7 @@ private: MediaBufferGroup mGroup; int mWidth, mHeight; size_t mSize; + int64_t mNumFramesOutput;; DummySource(const DummySource &); DummySource &operator=(const DummySource &); @@ -88,8 +104,8 @@ private: sp<MediaSource> createSource(const char *filename) { sp<MediaSource> source; - sp<MPEG4Extractor> extractor = - new MPEG4Extractor(new MmapSource(filename)); + sp<MediaExtractor> extractor = + MediaExtractor::Create(new FileSource(filename)); size_t num_tracks = extractor->countTracks(); @@ -117,6 +133,8 @@ sp<MediaSource> createSource(const char *filename) { int main(int argc, char **argv) { android::ProcessState::self()->startThreadPool(); + DataSource::RegisterDefaultSniffers(); + #if 1 if (argc != 2) { fprintf(stderr, "usage: %s filename\n", argv[0]); @@ -126,7 +144,7 @@ int main(int argc, char **argv) { OMXClient client; CHECK_EQ(client.connect(), OK); -#if 0 +#if 1 sp<MediaSource> source = createSource(argv[1]); if (source == NULL) { @@ -144,8 +162,8 @@ int main(int argc, char **argv) { success = success && meta->findInt32(kKeyHeight, &height); CHECK(success); #else - int width = 320; - int height = 240; + int width = 800; + int height = 480; sp<MediaSource> decoder = new DummySource(width, height); #endif @@ -159,19 +177,26 @@ int main(int argc, char **argv) { OMXCodec::Create( client.interface(), enc_meta, true /* createEncoder */, decoder); -#if 0 +#if 1 sp<MPEG4Writer> writer = new MPEG4Writer("/sdcard/output.mp4"); - writer->addSource(enc_meta, encoder); + writer->addSource(encoder); writer->start(); - sleep(20); - printf("stopping now.\n"); + while (!writer->reachedEOS()) { + usleep(100000); + } writer->stop(); #else encoder->start(); MediaBuffer *buffer; while (encoder->read(&buffer) == OK) { - printf("got an output frame of size %d\n", buffer->range_length()); + int32_t isSync; + if (!buffer->meta_data()->findInt32(kKeyIsSyncFrame, &isSync)) { + isSync = false; + } + + printf("got an output frame of size %d%s\n", buffer->range_length(), + isSync ? " (SYNC)" : ""); buffer->release(); buffer = NULL; diff --git a/cmds/stagefright/stagefright.cpp b/cmds/stagefright/stagefright.cpp index 4ffc8e4..76ec54b 100644 --- a/cmds/stagefright/stagefright.cpp +++ b/cmds/stagefright/stagefright.cpp @@ -24,15 +24,14 @@ #include <binder/ProcessState.h> #include <media/IMediaPlayerService.h> #include <media/stagefright/CachingDataSource.h> +#include <media/stagefright/FileSource.h> #include <media/stagefright/HTTPDataSource.h> #include <media/stagefright/JPEGSource.h> #include <media/stagefright/MediaDebug.h> #include <media/stagefright/MediaDefs.h> -#include <media/stagefright/MediaPlayerImpl.h> #include <media/stagefright/MediaExtractor.h> #include <media/stagefright/MediaSource.h> #include <media/stagefright/MetaData.h> -#include <media/stagefright/MmapSource.h> #include <media/stagefright/OMXClient.h> #include <media/stagefright/OMXCodec.h> @@ -52,46 +51,55 @@ static int64_t getNowUs() { static void playSource(OMXClient *client, const sp<MediaSource> &source) { sp<MetaData> meta = source->getFormat(); - int32_t durationUnits; - int32_t timeScale; - CHECK(meta->findInt32(kKeyDuration, &durationUnits)); - CHECK(meta->findInt32(kKeyTimeScale, &timeScale)); + const char *mime; + CHECK(meta->findCString(kKeyMIMEType, &mime)); - int64_t durationUs = ((int64_t)durationUnits * 1000000) / timeScale; - - sp<OMXCodec> decoder = OMXCodec::Create( + sp<MediaSource> rawSource; + if (!strcasecmp(MEDIA_MIMETYPE_AUDIO_RAW, mime)) { + rawSource = source; + } else { + rawSource = OMXCodec::Create( client->interface(), meta, false /* createEncoder */, source); - if (decoder == NULL) { - return; + if (rawSource == NULL) { + fprintf(stderr, "Failed to instantiate decoder for '%s'.\n", mime); + return; + } } - decoder->start(); + rawSource->start(); if (gReproduceBug >= 3 && gReproduceBug <= 5) { + int64_t durationUs; + CHECK(meta->findInt64(kKeyDuration, &durationUs)); + status_t err; MediaBuffer *buffer; MediaSource::ReadOptions options; int64_t seekTimeUs = -1; for (;;) { - err = decoder->read(&buffer, &options); + err = rawSource->read(&buffer, &options); options.clearSeekTo(); bool shouldSeek = false; - if (err != OK) { + if (err == INFO_FORMAT_CHANGED) { + CHECK_EQ(buffer, NULL); + + printf("format changed.\n"); + continue; + } else if (err != OK) { printf("reached EOF.\n"); shouldSeek = true; } else { - int32_t timestampUnits; - CHECK(buffer->meta_data()->findInt32(kKeyTimeUnits, ×tampUnits)); - - int64_t timestampUs = ((int64_t)timestampUnits * 1000000) / timeScale; + int64_t timestampUs; + CHECK(buffer->meta_data()->findInt64(kKeyTime, ×tampUs)); bool failed = false; if (seekTimeUs >= 0) { int64_t diff = timestampUs - seekTimeUs; + if (diff < 0) { diff = -diff; } @@ -134,7 +142,7 @@ static void playSource(OMXClient *client, const sp<MediaSource> &source) { } } - decoder->stop(); + rawSource->stop(); return; } @@ -151,12 +159,17 @@ static void playSource(OMXClient *client, const sp<MediaSource> &source) { MediaBuffer *buffer; for (;;) { - status_t err = decoder->read(&buffer, &options); + status_t err = rawSource->read(&buffer, &options); options.clearSeekTo(); if (err != OK) { CHECK_EQ(buffer, NULL); + if (err == INFO_FORMAT_CHANGED) { + printf("format changed.\n"); + continue; + } + break; } @@ -188,7 +201,7 @@ static void playSource(OMXClient *client, const sp<MediaSource> &source) { options.setSeekTo(0); } - decoder->stop(); + rawSource->stop(); printf("\n"); int64_t delay = getNowUs() - startTime; @@ -354,7 +367,7 @@ int main(int argc, char **argv) { dataSource = new HTTPDataSource(filename); dataSource = new CachingDataSource(dataSource, 64 * 1024, 10); } else { - dataSource = new MmapSource(filename); + dataSource = new FileSource(filename); } bool isJPEG = false; |