Andreas Huber | 8768f2c | 2009-12-01 15:26:54 -0800 | [diff] [blame^] | 1 | #include "SineSource.h" |
| 2 | |
| 3 | #include <binder/ProcessState.h> |
| 4 | #include <media/stagefright/AudioPlayer.h> |
| 5 | #include <media/stagefright/MediaDebug.h> |
| 6 | #include <media/stagefright/MediaDefs.h> |
| 7 | #include <media/stagefright/MetaData.h> |
| 8 | #include <media/stagefright/OMXClient.h> |
| 9 | #include <media/stagefright/OMXCodec.h> |
| 10 | |
| 11 | using namespace android; |
| 12 | |
| 13 | int main() { |
| 14 | // We only have an AMR-WB encoder on sholes... |
| 15 | static bool outputWBAMR = false; |
| 16 | static const int32_t kSampleRate = outputWBAMR ? 16000 : 8000; |
| 17 | static const int32_t kNumChannels = 1; |
| 18 | |
| 19 | android::ProcessState::self()->startThreadPool(); |
| 20 | |
| 21 | OMXClient client; |
| 22 | CHECK_EQ(client.connect(), OK); |
| 23 | |
| 24 | sp<MediaSource> source = new SineSource(kSampleRate, kNumChannels); |
| 25 | |
| 26 | sp<MetaData> meta = new MetaData; |
| 27 | |
| 28 | meta->setCString( |
| 29 | kKeyMIMEType, |
| 30 | outputWBAMR ? MEDIA_MIMETYPE_AUDIO_AMR_WB |
| 31 | : MEDIA_MIMETYPE_AUDIO_AMR_NB); |
| 32 | |
| 33 | meta->setInt32(kKeyChannelCount, kNumChannels); |
| 34 | meta->setInt32(kKeySampleRate, kSampleRate); |
| 35 | |
| 36 | int32_t maxInputSize; |
| 37 | if (source->getFormat()->findInt32(kKeyMaxInputSize, &maxInputSize)) { |
| 38 | meta->setInt32(kKeyMaxInputSize, maxInputSize); |
| 39 | } |
| 40 | |
| 41 | sp<OMXCodec> encoder = OMXCodec::Create( |
| 42 | client.interface(), |
| 43 | meta, true /* createEncoder */, |
| 44 | source); |
| 45 | |
| 46 | sp<OMXCodec> decoder = OMXCodec::Create( |
| 47 | client.interface(), |
| 48 | meta, false /* createEncoder */, |
| 49 | encoder); |
| 50 | |
| 51 | #if 1 |
| 52 | AudioPlayer *player = new AudioPlayer(NULL); |
| 53 | player->setSource(decoder); |
| 54 | |
| 55 | player->start(); |
| 56 | |
| 57 | sleep(10); |
| 58 | |
| 59 | player->stop(); |
| 60 | |
| 61 | delete player; |
| 62 | player = NULL; |
| 63 | #else |
| 64 | CHECK_EQ(decoder->start(), OK); |
| 65 | |
| 66 | MediaBuffer *buffer; |
| 67 | while (decoder->read(&buffer) == OK) { |
| 68 | // do something with buffer |
| 69 | |
| 70 | putchar('.'); |
| 71 | fflush(stdout); |
| 72 | |
| 73 | buffer->release(); |
| 74 | buffer = NULL; |
| 75 | } |
| 76 | |
| 77 | CHECK_EQ(decoder->stop(), OK); |
| 78 | #endif |
| 79 | |
| 80 | return 0; |
| 81 | } |