Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: AsciiFont GR-PEACH_video GraphicsFramework LCD_shield_config R_BSP TLV320_RBSP mbed-rtos mbed
MovPlayer.cpp
00001 #include "MovPlayer.hpp" 00002 00003 MovPlayer::VideoBuffer MovPlayer::videoBuf[]; 00004 MovPlayer::AudioBuffer MovPlayer::audioBuf[]; 00005 unsigned char MovPlayer::audioThreadStack[]; 00006 MovPlayer MovPlayer::singleton; 00007 00008 static void audioCallback(void MBED_UNUSED *p_data, int32_t result, void MBED_UNUSED *p_app_data) { 00009 if (result < 0) { 00010 printf("audio write callback error %ld\n", result); 00011 } 00012 // pc.printf("f"); 00013 } 00014 00015 MovPlayer::MovPlayer() : audioThread(osPriorityNormal, DEFAULT_STACK_SIZE, audioThreadStack), frameTimer(mbed::Callback<void ()>(this, &MovPlayer::frameTimerCallback), osTimerPeriodic), frameSemaphore(0), mov(nullptr) 00016 { 00017 } 00018 00019 void MovPlayer::frameTimerCallback() 00020 { 00021 frameSemaphore.release(); 00022 } 00023 00024 void MovPlayer::audioProcessor() 00025 { 00026 VideoBuffer *videoP = videoBuf; 00027 AudioBuffer *audioP = audioBuf; 00028 rbsp_data_conf_t audioConf = {&audioCallback, NULL}; 00029 frameTimer.start(1e3 / 30 + 1); 00030 int index = BufferLength; 00031 while (1) { 00032 do { 00033 if (mov->read(videoP->buf, audioP->buf, &audioP->size)) { 00034 videoQueue.put(videoP); 00035 output(audioP->buf, audioP->size, &audioConf); 00036 ++videoP; 00037 ++audioP; 00038 } else { 00039 queueTimeout = 0; 00040 __ISB(); 00041 __DSB(); 00042 rtos::Thread::wait(osWaitForever); 00043 } 00044 } while (--index); 00045 videoP = videoBuf; 00046 audioP = audioBuf; 00047 index = BufferLength; 00048 } 00049 } 00050 00051 void MovPlayer::play(MovFile *_mov, LCD *lcd, AudioCallback callback) 00052 { 00053 mov = _mov; 00054 output = callback; 00055 queueTimeout = osWaitForever; 00056 audioThread.start(mbed::Callback<void ()>(this, &MovPlayer::audioProcessor)); 00057 while (1) { 00058 osEvent event = videoQueue.get(queueTimeout); 00059 if (event.status == osEventMessage) { 00060 VideoBuffer *buf = reinterpret_cast<VideoBuffer *>(event.value.p); 00061 if (! (buf->buf[0] == 0xFF && buf->buf[1] == 0xD8)) { 00062 printf("m"); 00063 } 00064 frameSemaphore.wait(); 00065 lcd->drawImage(reinterpret_cast<graphics_image_t *>(buf->buf)); 00066 } else { 00067 audioThread.terminate(); 00068 frameTimer.stop(); 00069 while (frameSemaphore.wait(0) > 0) ; 00070 return; 00071 } 00072 } 00073 } 00074
Generated on Fri Jul 15 2022 12:17:04 by
1.7.2