Commit 35dc840c authored by François Grisez's avatar François Grisez

Use sintel_trailer video for the player tester

parent 511184eb
......@@ -33,6 +33,12 @@ typedef struct _MSMediaPlayer MSMediaPlayer;
* Callbacks definitions */
typedef void (*MSMediaPlayerEofCallback)(void *user_data);
typedef enum {
MS_FILE_FORMAT_UNKNOWN,
MS_FILE_FORMAT_WAVE,
MS_FILE_FORMAT_MATROSKA
} MSFileFormat;
/**
* @brief Instanciate a media player
* @param snd_card Playback sound card
......@@ -135,4 +141,11 @@ MS2_PUBLIC int ms_media_player_get_current_position(MSMediaPlayer *obj);
*/
MS2_PUBLIC bool_t ms_media_player_matroska_supported(void);
/**
* @brief Return format of the current opened file
* @param obj Player
* @return Format of the file. UNKNOWN_FORMAT when no file is opened
*/
MS2_PUBLIC MSFileFormat ms_media_player_get_file_format(const MSMediaPlayer *obj);
#endif
......@@ -21,27 +21,21 @@
#define ms_free_if_not_null(obj) if(obj != NULL) ms_free(obj)
typedef enum _FileFormat {
FILE_FORMAT_UNKNOWN,
FILE_FORMAT_WAVE,
FILE_FORMAT_MATROSKA
} FileFormat;
typedef uint8_t FourCC[4];
typedef struct _FormatDesc {
FileFormat format;
MSFileFormat format;
FourCC four_cc;
} FormatDesc;
static const FormatDesc _format_desc_list[] = {
{ FILE_FORMAT_WAVE , { 'R', 'I', 'F', 'F' } },
{ FILE_FORMAT_MATROSKA , { 0x1a, 0x45, 0xdf, 0xa3 } },
{ FILE_FORMAT_UNKNOWN , { 0x0, 0x0, 0x0, 0x0 } },
{ MS_FILE_FORMAT_WAVE , { 'R', 'I', 'F', 'F' } },
{ MS_FILE_FORMAT_MATROSKA , { 0x1a, 0x45, 0xdf, 0xa3 } },
{ MS_FILE_FORMAT_UNKNOWN , { 0x0, 0x0, 0x0, 0x0 } },
};
static bool_t four_cc_compare(const FourCC arg1, const FourCC arg2);
static FileFormat four_cc_to_file_format(const FourCC four_cc);
static MSFileFormat four_cc_to_file_format(const FourCC four_cc);
struct _MSMediaPlayer {
MSFilter *player;
......@@ -53,7 +47,7 @@ struct _MSMediaPlayer {
MSPinFormat audio_pin_fmt;
MSPinFormat video_pin_fmt;
MSTicker *ticker;
FileFormat format;
MSFileFormat format;
bool_t is_open;
char *filename;
MSMediaPlayerEofCallback eof_cb;
......@@ -64,7 +58,7 @@ struct _MSMediaPlayer {
unsigned long window_id;
};
static bool_t _get_format(const char *filepath, FileFormat *format);
static bool_t _get_format(const char *filepath, MSFileFormat *format);
static void _create_decoders(MSMediaPlayer *obj);
static void _create_sinks(MSMediaPlayer *obj);
static void _destroy_graph(MSMediaPlayer *obj);
......@@ -79,14 +73,14 @@ static bool_t four_cc_compare(const FourCC arg1, const FourCC arg2) {
&& arg1[3] == arg2[3];
}
static FileFormat four_cc_to_file_format(const FourCC four_cc) {
static MSFileFormat four_cc_to_file_format(const FourCC four_cc) {
int i;
for(i=0; _format_desc_list[i].format != FILE_FORMAT_UNKNOWN; i++) {
for(i=0; _format_desc_list[i].format != MS_FILE_FORMAT_UNKNOWN; i++) {
if(four_cc_compare(four_cc, _format_desc_list[i].four_cc)) {
return _format_desc_list[i].format;
}
}
return FILE_FORMAT_UNKNOWN;
return MS_FILE_FORMAT_UNKNOWN;
}
MSMediaPlayer *ms_media_player_new(MSSndCard *snd_card, const char *video_display_name, unsigned long window_id) {
......@@ -126,7 +120,7 @@ bool_t ms_media_player_open(MSMediaPlayer *obj, const char *filepath) {
return FALSE;
}
switch(obj->format) {
case FILE_FORMAT_WAVE:
case MS_FILE_FORMAT_WAVE:
fd = open(filepath, O_RDONLY);
if(fd == -1) {
ms_error("Cannot open %s", filepath);
......@@ -143,13 +137,13 @@ bool_t ms_media_player_open(MSMediaPlayer *obj, const char *filepath) {
}
obj->player = ms_filter_new(MS_FILE_PLAYER_ID);
break;
case FILE_FORMAT_MATROSKA:
case MS_FILE_FORMAT_MATROSKA:
if((obj->player = ms_filter_new(MS_MKV_PLAYER_ID)) == NULL) {
ms_error("Cannot open %s. Matroska file support is disabled", filepath);
return FALSE;
}
break;
case FILE_FORMAT_UNKNOWN:
case MS_FILE_FORMAT_UNKNOWN:
ms_error("Cannot open %s. Unknown format", filepath);
return FALSE;
}
......@@ -271,20 +265,24 @@ bool_t ms_media_player_matroska_supported(void) {
#endif
}
MSFileFormat ms_media_player_get_file_format(const MSMediaPlayer *obj) {
return obj->format;
}
/* Private functions */
static bool_t _get_format(const char *filepath, FileFormat *format) {
static bool_t _get_format(const char *filepath, MSFileFormat *format) {
FourCC four_cc;
size_t data_read;
FILE *file = fopen(filepath, "r");
if(file == NULL) {
ms_error("Cannot open %s", filepath);
*format = FILE_FORMAT_UNKNOWN;
*format = MS_FILE_FORMAT_UNKNOWN;
return FALSE;
}
data_read = fread(four_cc, 4, 1, file);
fclose(file);
if(data_read < 1) {
*format = FILE_FORMAT_UNKNOWN;
*format = MS_FILE_FORMAT_UNKNOWN;
return FALSE;
}
*format = four_cc_to_file_format(four_cc);
......@@ -294,13 +292,13 @@ static bool_t _get_format(const char *filepath, FileFormat *format) {
static void _create_decoders(MSMediaPlayer *obj) {
int sample_rate, nchannels;
switch(obj->format) {
case FILE_FORMAT_WAVE:
case MS_FILE_FORMAT_WAVE:
ms_filter_call_method(obj->player, MS_FILTER_GET_SAMPLE_RATE, &sample_rate);
ms_filter_call_method(obj->player, MS_FILTER_GET_NCHANNELS, &nchannels);
obj->audio_pin_fmt.pin = 0;
obj->audio_pin_fmt.fmt = ms_factory_get_audio_format(ms_factory_get_fallback(), "pcm", sample_rate, nchannels, NULL);
break;
case FILE_FORMAT_MATROSKA:
case MS_FILE_FORMAT_MATROSKA:
obj->audio_pin_fmt.pin = 1;
obj->video_pin_fmt.pin = 0;
ms_filter_call_method(obj->player, MS_FILTER_GET_OUTPUT_FMT, &obj->audio_pin_fmt);
......
......@@ -21,7 +21,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "mediastreamer2/msmediaplayer.h"
static int tester_init() {
ortp_set_log_level_mask(ORTP_MESSAGE | ORTP_WARNING | ORTP_ERROR | ORTP_FATAL);
ms_init();
return 0;
}
......@@ -61,12 +60,15 @@ static void wait_for_eof(Eof *obj, int refresh_time_ms, int timeout_ms) {
ms_mutex_unlock(&obj->mutex);
}
static void play_file(const char *filepath, bool_t unsupported_format, bool_t seeking_test, bool_t play_twice, int timeout) {
static void play_file(const char *filepath, bool_t unsupported_format, bool_t seeking_test, bool_t play_twice) {
bool_t succeed;
Eof eof;
MSMediaPlayer *file_player = NULL;
MSSndCard *snd_card = ms_snd_card_manager_get_default_card(ms_snd_card_manager_get());
const char *display_name = video_stream_get_default_video_renderer();
int duration, timeout;
const int seek_time = 6100;
const double timeout_prec = 0.05;
eof_init(&eof);
......@@ -90,13 +92,26 @@ static void play_file(const char *filepath, bool_t unsupported_format, bool_t se
return;
}
duration = ms_media_player_get_duration(file_player);
if(ms_media_player_get_file_format(file_player) == MS_FILE_FORMAT_WAVE) {
CU_ASSERT_TRUE(duration == -1);
duration = 20000;
} else {
CU_ASSERT_TRUE(duration >= 0);
}
if(seeking_test) {
timeout = (duration - seek_time) * (1 + timeout_prec);
} else {
timeout = duration * (1 + timeout_prec);
}
succeed = ms_media_player_start(file_player);
CU_ASSERT_TRUE(succeed);
CU_ASSERT_EQUAL(ms_media_player_get_state(file_player), MSPlayerPlaying);
if(seeking_test) {
CU_ASSERT_TRUE(ms_media_player_seek(file_player, 5000));
CU_ASSERT_TRUE(ms_media_player_seek(file_player, seek_time));
}
if(succeed) {
......@@ -117,53 +132,53 @@ static void play_file(const char *filepath, bool_t unsupported_format, bool_t se
ms_media_player_free(file_player);
}
static void play_root_file(const char *filepath, bool_t unsupported_format, bool_t seeking_test, bool_t play_twice, int timeout){
static void play_root_file(const char *filepath, bool_t unsupported_format, bool_t seeking_test, bool_t play_twice){
char* file = ms_strdup_printf("%s/%s", mediastreamer2_tester_get_file_root(), filepath);
play_file(file, unsupported_format, seeking_test, play_twice, timeout);
play_file(file, unsupported_format, seeking_test, play_twice);
ms_free(file);
}
static void play_hello_8000_wav(void) {
play_root_file("sounds/hello8000.wav", FALSE, FALSE, FALSE, 20000);
play_root_file("sounds/hello8000.wav", FALSE, FALSE, FALSE);
}
static void play_hello_16000_wav(void) {
play_root_file("sounds/hello16000.wav", FALSE, FALSE, FALSE, 20000);
play_root_file("sounds/hello16000.wav", FALSE, FALSE, FALSE);
}
static void play_hello_pcmu_mka(void) {
play_root_file("sounds/hello_pcmu.mka", !ms_media_player_matroska_supported(), FALSE, FALSE, 20000);
play_root_file("sounds/hello_pcmu.mka", !ms_media_player_matroska_supported(), FALSE, FALSE);
}
static void play_hello_opus_mka(void) {
play_root_file("sounds/hello_opus.mka", !ms_media_player_matroska_supported(), FALSE, FALSE, 20000);
play_root_file("sounds/hello_opus.mka", !ms_media_player_matroska_supported(), FALSE, FALSE);
}
static void play_hello_pcmu_h264_mkv(void) {
play_root_file("sounds/hello_pcmu_h264.mkv", !ms_media_player_matroska_supported(), FALSE, FALSE, 20000);
static void play_sintel_trailer_pcmu_h264_mkv(void) {
play_root_file("sounds/sintel_trailer_pcmu_h264.mkv", !ms_media_player_matroska_supported(), FALSE, FALSE);
}
static void play_hello_opus_h264_mkv(void) {
play_root_file("sounds/hello_opus_h264.mkv", !ms_media_player_matroska_supported(), FALSE, FALSE, 20000);
static void play_sintel_trailer_opus_h264_mkv(void) {
play_root_file("sounds/sintel_trailer_opus_h264.mkv", !ms_media_player_matroska_supported(), FALSE, FALSE);
}
static void seeking_test(void) {
play_root_file("sounds/hello_opus_h264.mkv", !ms_media_player_matroska_supported(), TRUE, FALSE, 15000);
play_root_file("sounds/sintel_trailer_opus_h264.mkv", !ms_media_player_matroska_supported(), TRUE, FALSE);
}
static void playing_twice_test(void) {
play_root_file("./sounds/hello_opus_h264.mkv", !ms_media_player_matroska_supported(), FALSE, TRUE, 15000);
play_root_file("./sounds/sintel_trailer_opus_h264.mkv", !ms_media_player_matroska_supported(), FALSE, TRUE);
}
static test_t tests[] = {
{ "Play hello8000.wav" , play_hello_8000_wav },
{ "Play hello16000.wav" , play_hello_16000_wav },
{ "Play hello_pcmu.mka" , play_hello_pcmu_mka },
{ "Play hello_opus.mka" , play_hello_opus_mka },
{ "Play hello_pcmu_h264.mkv" , play_hello_pcmu_h264_mkv },
{ "Play hello_opus_h264.mkv" , play_hello_opus_h264_mkv },
{ "Seeking" , seeking_test },
{ "Playing twice" , playing_twice_test }
{ "Play hello8000.wav" , play_hello_8000_wav },
{ "Play hello16000.wav" , play_hello_16000_wav },
{ "Play hello_pcmu.mka" , play_hello_pcmu_mka },
{ "Play hello_opus.mka" , play_hello_opus_mka },
{ "Play sintel_trailer_pcmu_h264.mkv" , play_sintel_trailer_pcmu_h264_mkv },
{ "Play sintel_trailer_opus_h264.mkv" , play_sintel_trailer_opus_h264_mkv },
{ "Seeking" , seeking_test },
{ "Playing twice" , playing_twice_test }
};
test_suite_t player_test_suite = {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment