Commit 0d3777bd authored by François Grisez's avatar François Grisez

Add MSPlayer class

This class enable to read some media files.
Supported format are WAVE and MATROSKA
Supported codec :
	+ WAVE: only PCM s16l
	+ MATROSKA: pcmu, opus and h264
parent dbded55e
#ifndef FILEPLAYER_H
#define FILEPLAYER_H
#include "mscommon.h"
#include "mssndcard.h"
typedef struct _FilePlayer FilePlayer;
typedef void (*FilePlayerEofCallback)(void *user_data);
MS2_PUBLIC FilePlayer *ms_file_player_new(MSSndCard *snd_card, const char *video_display_name);
MS2_PUBLIC void ms_file_player_free(FilePlayer *obj);
MS2_PUBLIC void ms_file_player_set_eof_callback(FilePlayer *obj, FilePlayerEofCallback cb, void *user_data);
MS2_PUBLIC bool_t ms_file_player_open(FilePlayer *obj, const char *filepath);
MS2_PUBLIC void ms_file_player_close(FilePlayer *obj);
MS2_PUBLIC bool_t ms_file_player_start(FilePlayer *obj);
MS2_PUBLIC void ms_file_player_stop(FilePlayer *obj);
MS2_PUBLIC void ms_file_player_pause(FilePlayer *obj);
MS2_PUBLIC void ms_file_player_seek(FilePlayer *obj, int seek_pos_ms);
#endif
......@@ -287,7 +287,8 @@ libmediastreamer_voip_la_SOURCES+= voip/rfc2429.h \
videofilters/extdisplay.c \
utils/bits_rw.c \
utils/x11_helper.c \
voip/layouts.c voip/layouts.h
voip/layouts.c voip/layouts.h \
voip/msfileplayer.c
if ORTP_ENABLED
libmediastreamer_voip_la_SOURCES+= voip/videostream.c
......
......@@ -117,7 +117,13 @@ typedef struct _wave_header_t
data_t data_chunk;
} wave_header_t;
#define WAVE_FORMAT_PCM 0x0001
#define WAVE_FORMAT_IEEE_FLOAT 0x0003
#define WAVE_FORMAT_ALAW 0x0006
#define WAVE_FORMAT_MULAW 0x0007
#define WAVE_FORMAT_EXTENSIBLE 0xFFFE
#define wave_header_get_format_type(header) le_uint16((header)->format_chunk.type)
#define wave_header_get_rate(header) le_uint32((header)->format_chunk.rate)
#define wave_header_get_channel(header) le_uint16((header)->format_chunk.channel)
#define wave_header_get_bpsmpl(header) \
......
......@@ -445,13 +445,13 @@ static void wav_private_set(WavPrivate *data, const MSFmtDescriptor *obj) {
}
static void wav_private_serialize(const WavPrivate *obj, uint8_t **data, size_t *size) {
*size = 22;
*size = sizeof(WavPrivate);
*data = (uint8_t *)ms_new0(uint8_t, *size);
memcpy(*data, obj, *size);
}
static inline void wav_private_load(WavPrivate *obj, const uint8_t *data) {
memcpy(obj, data, 22);
memcpy(obj, data, sizeof(WavPrivate));
}
/* µLaw module */
......@@ -2405,12 +2405,12 @@ static int player_get_state(MSFilter *f, void *arg) {
static MSFilterMethod player_methods[]= {
{ MS_FILTER_GET_OUTPUT_FMT , player_get_output_fmt },
{ MS_PLAYER_OPEN , player_open_file },
{ MS_PLAYER_CLOSE , player_close },
{ MS_PLAYER_START , player_start },
{ MS_PLAYER_PAUSE , player_stop },
{ MS_PLAYER_GET_STATE , player_get_state },
{ 0 , NULL }
{ MS_PLAYER_OPEN , player_open_file },
{ MS_PLAYER_CLOSE , player_close },
{ MS_PLAYER_START , player_start },
{ MS_PLAYER_PAUSE , player_stop },
{ MS_PLAYER_GET_STATE , player_get_state },
{ 0 , NULL }
};
#ifdef _MSC_VER
......
This diff is collapsed.
......@@ -15,7 +15,8 @@ mediastreamer2_tester_SOURCES= \
mediastreamer2_sound_card_tester.c \
mediastreamer2_adaptive_tester.c \
mediastreamer2_audio_stream_tester.c \
mediastreamer2_framework_tester.c
mediastreamer2_framework_tester.c \
mediastreamer2_player_tester.c
AM_CPPFLAGS=\
-I$(top_srcdir)/ \
......@@ -44,24 +45,20 @@ endif BUILD_MACOSX
if BUILD_VIDEO
mediastreamer2_tester_SOURCES+= mediastreamer2_video_stream_tester.c
if BUILD_MATROSKA
mediastreamer2_tester_SOURCES+= mediastreamer2_player_recorder_tester.c
endif
endif
AM_LDFLAGS=-no-undefined -export-dynamic
AM_CFLAGS=$(STRICT_OPTIONS) $(STRICT_OPTIONS_CC) $(ORTP_CFLAGS) $(CUNIT_CFLAGS)
if BUILD_VIDEO
AM_CFLAGS+=$(VIDEO_CFLAGS) $(GLEW_CFLAGS)
endif
if BUILD_MATROSKA
AM_CFLAGS+=-DHAVE_MATROSKA
endif
endif
test: mediastreamer2_tester
......
This diff is collapsed.
#include "mediastreamer2_tester.h"
#include "../include/mediastreamer2/fileplayer.h"
static int tester_init() {
ms_init();
return 0;
}
static int tester_cleanup() {
ms_exit();
return 0;
}
typedef struct _Eof {
bool_t eof;
int time_ms;
ms_mutex_t mutex;
} Eof;
static void eof_init(Eof *obj) {
obj->eof = FALSE;
obj->time_ms = 0;
ms_mutex_init(&obj->mutex, NULL);
}
static void eof_callback(void *user_data) {
Eof *obj = (Eof *)user_data;
ms_mutex_lock(&obj->mutex);
obj->eof = TRUE;
ms_mutex_unlock(&obj->mutex);
}
static void wait_for_eof(Eof *obj, int refresh_time_ms, int timeout_ms) {
ms_mutex_lock(&obj->mutex);
while(obj->time_ms < timeout_ms && !obj->eof) {
ms_mutex_unlock(&obj->mutex);
usleep((useconds_t)(refresh_time_ms) * 1000U);
obj->time_ms += refresh_time_ms;
ms_mutex_lock(&obj->mutex);
}
ms_mutex_unlock(&obj->mutex);
}
static void play_file(const char *filepath, bool_t unsupported_format) {
bool_t succeed;
Eof eof;
FilePlayer *file_player = NULL;
// MSSndCard *snd_card = ms_snd_card_manager_get_default_card(ms_snd_card_manager_get());
MSSndCard *snd_card = ms_snd_card_manager_get_card(ms_snd_card_manager_get(), "ALSA: default device");
const char *display_name = video_stream_get_default_video_renderer();
eof_init(&eof);
file_player = ms_file_player_new(snd_card, display_name);
CU_ASSERT_PTR_NOT_NULL(file_player);
if(file_player == NULL) return;
ms_file_player_set_eof_callback(file_player, eof_callback, &eof);
succeed = ms_file_player_open(file_player, filepath);
if(unsupported_format) {
CU_ASSERT_FALSE(succeed);
} else {
CU_ASSERT_TRUE(succeed);
}
if(!succeed) {
ms_file_player_free(file_player);
return;
}
succeed = ms_file_player_start(file_player);
CU_ASSERT_TRUE(succeed);
if(succeed) {
wait_for_eof(&eof, 100, 20000);
}
ms_file_player_close(file_player);
ms_file_player_free(file_player);
CU_ASSERT_TRUE(eof.eof);
}
static void play_hello_8000_wav(void) {
play_file("./sounds/hello8000.wav", FALSE);
}
static void play_hello_16000_wav(void) {
play_file("./sounds/hello16000.wav", FALSE);
}
static void play_hello_pcmu_mka(void) {
#ifdef HAVE_MATROSKA
play_file("./sounds/hello_pcmu.mka", FALSE);
#else
play_file("./sounds/hello_pcmu.mka", TRUE);
#endif
}
static void play_hello_opus_mka(void) {
#ifdef HAVE_MATROSKA
play_file("./sounds/hello_opus.mka", FALSE);
#else
play_file("./sounds/hello_opus.mka", TRUE);
#endif
}
static void play_hello_pcmu_h264_mkv(void) {
#ifdef HAVE_MATROSKA
play_file("./sounds/hello_pcmu_h264.mkv", FALSE);
#else
play_file("./sounds/hello_pcmu_h264.mkv", TRUE);
#endif
}
static void play_hello_opus_h264_mkv(void) {
#ifdef HAVE_MATROSKA
play_file("./sounds/hello_opus_h264.mkv", FALSE);
#else
play_file("./sounds/hello_opus_h264.mkv", TRUE);
#endif
}
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 }
};
test_suite_t player_test_suite = {
"Player",
tester_init,
tester_cleanup,
sizeof(tests)/sizeof(test_t),
tests
};
......@@ -127,9 +127,7 @@ void mediastreamer2_tester_init(void) {
add_test_suite(&video_stream_test_suite);
#endif
add_test_suite(&framework_test_suite);
#ifdef HAVE_MATROSKA
add_test_suite(&player_recorder_test_suite);
#endif
add_test_suite(&player_test_suite);
for (i = 0; i < mediastreamer2_tester_nb_test_suites(); i++) {
run_test_suite(test_suite[i]);
......
......@@ -53,9 +53,7 @@ extern test_suite_t adaptive_test_suite;
extern test_suite_t audio_stream_test_suite;
extern test_suite_t video_stream_test_suite;
extern test_suite_t framework_test_suite;
#ifdef HAVE_MATROSKA
extern test_suite_t player_recorder_test_suite;
#endif
extern test_suite_t player_test_suite;
#define CU_ASSERT_IN_RANGE(value, inf, sup) \
CU_ASSERT_TRUE(value >= inf); \
......
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