Commit dfe562b7 authored by François Grisez's avatar François Grisez
Browse files

Rename MSFilePlayer into MSMediaPlayer

parent 2054fd60
......@@ -42,7 +42,7 @@ mediastreamer2_include_HEADERS= ice.h \
flowcontrol.h \
formats.h \
msfactory.h \
fileplayer.h
msmediaplayer.h
EXTRA_DIST=$(mediastreamer2_include_HEADERS)
......@@ -8,12 +8,11 @@
/**
* @brief Media file player
*/
typedef struct _MSFilePlayer MSFilePlayer;
typedef struct _MSMediaPlayer MSMediaPlayer;
/**
* Callbacks definitions
*/
typedef void (*MSFilePlayerEofCallback)(void *user_data);
* Callbacks definitions */
typedef void (*MSMediaPlayerEofCallback)(void *user_data);
/**
* @brief Instanciate a file player
......@@ -22,20 +21,20 @@ typedef void (*MSFilePlayerEofCallback)(void *user_data);
* @param window_id Pointer on the drawing window
* @return A pointer on the created MSFilePlayer
*/
MS2_PUBLIC MSFilePlayer *ms_file_player_new(MSSndCard *snd_card, const char *video_display_name, void *window_id);
MS2_PUBLIC MSMediaPlayer *ms_media_player_new(MSSndCard *snd_card, const char *video_display_name, void *window_id);
/**
* @brief Free a file player
* @param obj Pointer on the MSFilePlayer to free
*/
MS2_PUBLIC void ms_file_player_free(MSFilePlayer *obj);
MS2_PUBLIC void ms_media_player_free(MSMediaPlayer *obj);
/**
* @brief Get the window ID
* @param obj The player
* @return The window ID
*/
MS2_PUBLIC void *ms_file_player_get_window_id(const MSFilePlayer *obj);
MS2_PUBLIC void *ms_media_player_get_window_id(const MSMediaPlayer *obj);
/**
* @brief Set the "End of File" callback
......@@ -43,7 +42,7 @@ MS2_PUBLIC void *ms_file_player_get_window_id(const MSFilePlayer *obj);
* @param cb Function to call
* @param user_data Data which will be passed to the function
*/
MS2_PUBLIC void ms_file_player_set_eof_callback(MSFilePlayer *obj, MSFilePlayerEofCallback cb, void *user_data);
MS2_PUBLIC void ms_media_player_set_eof_callback(MSMediaPlayer *obj, MSMediaPlayerEofCallback cb, void *user_data);
/**
* @brief Open a media file
......@@ -51,21 +50,21 @@ MS2_PUBLIC void ms_file_player_set_eof_callback(MSFilePlayer *obj, MSFilePlayerE
* @param filepath Path of the file to open
* @return TRUE if the file could be opened
*/
MS2_PUBLIC bool_t ms_file_player_open(MSFilePlayer *obj, const char *filepath);
MS2_PUBLIC bool_t ms_media_player_open(MSMediaPlayer *obj, const char *filepath);
/**
* @brief Close a media file
* That function can be safly call even if no file has been opend
* @param obj A pointer to a MSFilePlayer
*/
MS2_PUBLIC void ms_file_player_close(MSFilePlayer *obj);
MS2_PUBLIC void ms_media_player_close(MSMediaPlayer *obj);
/**
* @brief Start playback
* @param obj A pointer on a MSFilePlayer
* @return TRUE if playback has been successfuly started
*/
MS2_PUBLIC bool_t ms_file_player_start(MSFilePlayer *obj);
MS2_PUBLIC bool_t ms_media_player_start(MSMediaPlayer *obj);
/**
* @brief Stop a playback
......@@ -73,13 +72,13 @@ MS2_PUBLIC bool_t ms_file_player_start(MSFilePlayer *obj);
* the begining of the file.
* @param obj A pointer on a MSFilePlayer
*/
MS2_PUBLIC void ms_file_player_stop(MSFilePlayer *obj);
MS2_PUBLIC void ms_media_player_stop(MSMediaPlayer *obj);
/**
* @brief Turn playback to paused.
* @param obj A pointer on a MSFilePlayer
*/
MS2_PUBLIC void ms_file_player_pause(MSFilePlayer *obj);
MS2_PUBLIC void ms_media_player_pause(MSMediaPlayer *obj);
/**
* @brief Seek into the opened file
......@@ -88,33 +87,33 @@ MS2_PUBLIC void ms_file_player_pause(MSFilePlayer *obj);
* @param seek_pos_ms Position where to seek on (in milliseconds)
* @return
*/
MS2_PUBLIC bool_t ms_file_player_seek(MSFilePlayer *obj, int seek_pos_ms);
MS2_PUBLIC bool_t ms_media_player_seek(MSMediaPlayer *obj, int seek_pos_ms);
/**
* @brief Get the state of the player
* @param obj A pointer on a MSFilePlayer
* @return An MSPLayerSate enum
*/
MS2_PUBLIC MSPlayerState ms_file_player_get_state(MSFilePlayer *obj);
MS2_PUBLIC MSPlayerState ms_media_player_get_state(MSMediaPlayer *obj);
/**
* @brief Get the duration of the opened media
* @param obj A pointer on a MSFilePlayer
* @return The duration in milliseconds. -1 if failure
*/
MS2_PUBLIC int ms_file_player_get_duration(MSFilePlayer *obj);
MS2_PUBLIC int ms_media_player_get_duration(MSMediaPlayer *obj);
/**
* @brief Get the position of the playback
* @param obj The player
* @return The position in milliseconds. -1 if failure
*/
MS2_PUBLIC int ms_file_player_get_current_position(MSFilePlayer *obj);
MS2_PUBLIC int ms_media_player_get_current_position(MSMediaPlayer *obj);
/**
* @brief Check whether Matroska format is supported by the player
* @return TRUE if supported
*/
MS2_PUBLIC bool_t ms_file_player_matroska_supported(void);
MS2_PUBLIC bool_t ms_media_player_matroska_supported(void);
#endif
......@@ -86,7 +86,7 @@ libmediastreamer_voip_la_SOURCES+= voip/private.h \
voip/mediastream.c \
voip/audiostream.c \
voip/ringstream.c \
voip/msfileplayer.c \
voip/msmediaplayer.c \
voip/ice.c \
otherfilters/msrtp.c \
voip/qualityindicator.c \
......
#include "mediastreamer2/fileplayer.h"
#include "mediastreamer2/msmediaplayer.h"
#include "mediastreamer2/msfilter.h"
#include "mediastreamer2/msticker.h"
#include "mediastreamer2/msextdisplay.h"
......@@ -38,7 +38,7 @@ static const FormatDesc _format_desc_list[] = {
static bool_t four_cc_compare(const FourCC arg1, const FourCC arg2);
static FileFormat four_cc_to_file_format(const FourCC four_cc);
struct _MSFilePlayer {
struct _MSMediaPlayer {
MSFilter *player;
MSFilter *audio_decoder;
MSFilter *audio_sink;
......@@ -51,7 +51,7 @@ struct _MSFilePlayer {
FileFormat format;
bool_t is_open;
char *filename;
MSFilePlayerEofCallback eof_cb;
MSMediaPlayerEofCallback eof_cb;
void *user_data_cb;
ms_mutex_t cb_access;
MSSndCard *snd_card;
......@@ -60,11 +60,11 @@ struct _MSFilePlayer {
};
static bool_t _get_format(const char *filepath, FileFormat *format);
static void _create_decoders(MSFilePlayer *obj);
static void _create_sinks(MSFilePlayer *obj);
static void _destroy_graph(MSFilePlayer *obj);
static bool_t _link_all(MSFilePlayer *obj);
static void _unlink_all(MSFilePlayer *obj);
static void _create_decoders(MSMediaPlayer *obj);
static void _create_sinks(MSMediaPlayer *obj);
static void _destroy_graph(MSMediaPlayer *obj);
static bool_t _link_all(MSMediaPlayer *obj);
static void _unlink_all(MSMediaPlayer *obj);
static void _eof_filter_notify_cb(void *userdata, struct _MSFilter *f, unsigned int id, void *arg);
static bool_t four_cc_compare(const FourCC arg1, const FourCC arg2) {
......@@ -84,8 +84,8 @@ static FileFormat four_cc_to_file_format(const FourCC four_cc) {
return FILE_FORMAT_UNKNOWN;
}
MSFilePlayer *ms_file_player_new(MSSndCard *snd_card, const char *video_display_name, void *window_id) {
MSFilePlayer *obj = (MSFilePlayer *)ms_new0(MSFilePlayer, 1);
MSMediaPlayer *ms_media_player_new(MSSndCard *snd_card, const char *video_display_name, void *window_id) {
MSMediaPlayer *obj = (MSMediaPlayer *)ms_new0(MSMediaPlayer, 1);
obj->ticker = ms_ticker_new();
ms_mutex_init(&obj->cb_access, NULL);
obj->snd_card = snd_card;
......@@ -96,18 +96,18 @@ MSFilePlayer *ms_file_player_new(MSSndCard *snd_card, const char *video_display_
return obj;
}
void ms_file_player_free(MSFilePlayer *obj) {
ms_file_player_close(obj);
void ms_media_player_free(MSMediaPlayer *obj) {
ms_media_player_close(obj);
ms_ticker_destroy(obj->ticker);
ms_free_if_not_null(obj->video_display);
ms_free(obj);
}
void *ms_file_player_get_window_id(const MSFilePlayer *obj) {
void *ms_media_player_get_window_id(const MSMediaPlayer *obj) {
return obj->window_id;
}
bool_t ms_file_player_open(MSFilePlayer *obj, const char *filepath) {
bool_t ms_media_player_open(MSMediaPlayer *obj, const char *filepath) {
wave_header_t header;
int fd;
char *tmp;
......@@ -170,7 +170,7 @@ bool_t ms_file_player_open(MSFilePlayer *obj, const char *filepath) {
return TRUE;
}
void ms_file_player_close(MSFilePlayer *obj) {
void ms_media_player_close(MSMediaPlayer *obj) {
if(obj->is_open) {
ms_ticker_detach(obj->ticker, obj->player);
ms_filter_call_method_noarg(obj->player, MS_PLAYER_CLOSE);
......@@ -181,7 +181,7 @@ void ms_file_player_close(MSFilePlayer *obj) {
}
}
bool_t ms_file_player_start(MSFilePlayer *obj) {
bool_t ms_media_player_start(MSMediaPlayer *obj) {
if(!obj->is_open) {
ms_error("Cannot start playing. No file has been opened");
return FALSE;
......@@ -193,7 +193,7 @@ bool_t ms_file_player_start(MSFilePlayer *obj) {
return TRUE;
}
void ms_file_player_stop(MSFilePlayer *obj) {
void ms_media_player_stop(MSMediaPlayer *obj) {
int seek_pos = 0;
if(obj->is_open) {
ms_filter_call_method_noarg(obj->player, MS_PLAYER_PAUSE);
......@@ -201,13 +201,13 @@ void ms_file_player_stop(MSFilePlayer *obj) {
}
}
void ms_file_player_pause(MSFilePlayer *obj) {
void ms_media_player_pause(MSMediaPlayer *obj) {
if(obj->is_open) {
ms_filter_call_method_noarg(obj->player, MS_PLAYER_PAUSE);
}
}
bool_t ms_file_player_seek(MSFilePlayer *obj, int seek_pos_ms) {
bool_t ms_media_player_seek(MSMediaPlayer *obj, int seek_pos_ms) {
if(obj->is_open) {
return ms_filter_call_method(obj->player, MS_PLAYER_SEEK_MS, &seek_pos_ms) == 0 ? TRUE : FALSE;
} else {
......@@ -215,7 +215,7 @@ bool_t ms_file_player_seek(MSFilePlayer *obj, int seek_pos_ms) {
}
}
MSPlayerState ms_file_player_get_state(MSFilePlayer *obj) {
MSPlayerState ms_media_player_get_state(MSMediaPlayer *obj) {
if(obj->is_open) {
MSPlayerState state;
ms_filter_call_method(obj->player, MS_PLAYER_GET_STATE, &state);
......@@ -225,7 +225,7 @@ MSPlayerState ms_file_player_get_state(MSFilePlayer *obj) {
}
}
int ms_file_player_get_duration(MSFilePlayer *obj) {
int ms_media_player_get_duration(MSMediaPlayer *obj) {
int duration;
if(!obj->is_open) {
ms_error("Could not get duration. No file is open");
......@@ -238,7 +238,7 @@ int ms_file_player_get_duration(MSFilePlayer *obj) {
return duration;
}
int ms_file_player_get_current_position(MSFilePlayer *obj) {
int ms_media_player_get_current_position(MSMediaPlayer *obj) {
int position;
if(!obj->is_open) {
ms_error("Could not get position. No file is open");
......@@ -251,14 +251,14 @@ int ms_file_player_get_current_position(MSFilePlayer *obj) {
return position;
}
void ms_file_player_set_eof_callback(MSFilePlayer *obj, MSFilePlayerEofCallback cb, void *user_data) {
void ms_media_player_set_eof_callback(MSMediaPlayer *obj, MSMediaPlayerEofCallback cb, void *user_data) {
ms_mutex_lock(&obj->cb_access);
obj->eof_cb = cb;
obj->user_data_cb = user_data;
ms_mutex_unlock(&obj->cb_access);
}
bool_t ms_file_player_matroska_supported(void) {
bool_t ms_media_player_matroska_supported(void) {
#ifdef HAVE_MATROSKA
return TRUE;
#else
......@@ -286,7 +286,7 @@ static bool_t _get_format(const char *filepath, FileFormat *format) {
return TRUE;
}
static void _create_decoders(MSFilePlayer *obj) {
static void _create_decoders(MSMediaPlayer *obj) {
int sample_rate, nchannels;
switch(obj->format) {
case FILE_FORMAT_WAVE:
......@@ -324,7 +324,7 @@ static void _create_decoders(MSFilePlayer *obj) {
}
}
static void _create_sinks(MSFilePlayer *obj) {
static void _create_sinks(MSMediaPlayer *obj) {
int sink_sample_rate, sample_rate, nchannels;
if(obj->audio_pin_fmt.fmt && obj->snd_card) {
sample_rate = obj->audio_pin_fmt.fmt->rate;
......@@ -356,7 +356,7 @@ static void _create_sinks(MSFilePlayer *obj) {
}
}
static void _destroy_graph(MSFilePlayer *obj) {
static void _destroy_graph(MSMediaPlayer *obj) {
ms_filter_destroy_and_reset_if_not_null(obj->player);
ms_filter_destroy_and_reset_if_not_null(obj->audio_decoder);
ms_filter_destroy_and_reset_if_not_null(obj->video_decoder);
......@@ -367,7 +367,7 @@ static void _destroy_graph(MSFilePlayer *obj) {
obj->video_pin_fmt.fmt = NULL;
}
static bool_t _link_all(MSFilePlayer *obj) {
static bool_t _link_all(MSMediaPlayer *obj) {
MSConnectionHelper helper;
if(obj->player == NULL) {
ms_error("Could not link graph. There is no playing filter");
......@@ -393,7 +393,7 @@ static bool_t _link_all(MSFilePlayer *obj) {
return TRUE;
}
static void _unlink_all(MSFilePlayer *obj) {
static void _unlink_all(MSMediaPlayer *obj) {
MSConnectionHelper helper;
if(obj->audio_pin_fmt.fmt && obj->audio_sink) {
ms_connection_helper_start(&helper);
......@@ -411,7 +411,7 @@ static void _unlink_all(MSFilePlayer *obj) {
}
static void _eof_filter_notify_cb(void *userdata, struct _MSFilter *f, unsigned int id, void *arg) {
MSFilePlayer *obj = (MSFilePlayer *)userdata;
MSMediaPlayer *obj = (MSMediaPlayer *)userdata;
ms_mutex_lock(&obj->cb_access);
if(f == obj->player && id == MS_PLAYER_EOF && obj->eof_cb != NULL) {
obj->eof_cb(obj->user_data_cb);
......
/*
mediastreamer2 library - modular sound and video processing and streaming
Copyright (C) 2006-2013 Belledonne Communications, Grenoble
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "mediastreamer2_tester.h"
#include "../include/mediastreamer2/fileplayer.h"
#include "mediastreamer2/msmediaplayer.h"
static int tester_init() {
ortp_set_log_level_mask(ORTP_MESSAGE | ORTP_WARNING | ORTP_ERROR | ORTP_FATAL);
......@@ -45,42 +64,42 @@ static void wait_for_eof(Eof *obj, int refresh_time_ms, int timeout_ms) {
static void play_file(const char *filepath, bool_t unsupported_format, bool_t seeking_test, int timeout) {
bool_t succeed;
Eof eof;
MSFilePlayer *file_player = NULL;
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();
eof_init(&eof);
file_player = ms_file_player_new(snd_card, display_name, NULL);
file_player = ms_media_player_new(snd_card, display_name, NULL);
CU_ASSERT_PTR_NOT_NULL(file_player);
if(file_player == NULL) return;
ms_file_player_set_eof_callback(file_player, eof_callback, &eof);
ms_media_player_set_eof_callback(file_player, eof_callback, &eof);
succeed = ms_file_player_open(file_player, filepath);
succeed = ms_media_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);
ms_media_player_free(file_player);
return;
}
succeed = ms_file_player_start(file_player);
succeed = ms_media_player_start(file_player);
CU_ASSERT_TRUE(succeed);
if(seeking_test) {
CU_ASSERT_TRUE(ms_file_player_seek(file_player, 5000));
CU_ASSERT_TRUE(ms_media_player_seek(file_player, 5000));
}
if(succeed) {
wait_for_eof(&eof, 100, timeout);
}
ms_file_player_close(file_player);
ms_file_player_free(file_player);
ms_media_player_close(file_player);
ms_media_player_free(file_player);
CU_ASSERT_TRUE(eof.eof);
}
......@@ -93,23 +112,23 @@ static void play_hello_16000_wav(void) {
}
static void play_hello_pcmu_mka(void) {
play_file("./sounds/hello_pcmu.mka", !ms_file_player_matroska_supported(), FALSE, 20000);
play_file("./sounds/hello_pcmu.mka", !ms_media_player_matroska_supported(), FALSE, 20000);
}
static void play_hello_opus_mka(void) {
play_file("./sounds/hello_opus.mka", !ms_file_player_matroska_supported(), FALSE, 20000);
play_file("./sounds/hello_opus.mka", !ms_media_player_matroska_supported(), FALSE, 20000);
}
static void play_hello_pcmu_h264_mkv(void) {
play_file("./sounds/hello_pcmu_h264.mkv", !ms_file_player_matroska_supported(), FALSE, 20000);
play_file("./sounds/hello_pcmu_h264.mkv", !ms_media_player_matroska_supported(), FALSE, 20000);
}
static void play_hello_opus_h264_mkv(void) {
play_file("./sounds/hello_opus_h264.mkv", !ms_file_player_matroska_supported(), FALSE, 20000);
play_file("./sounds/hello_opus_h264.mkv", !ms_media_player_matroska_supported(), FALSE, 20000);
}
static void seeking_test(void) {
play_file("./sounds/hello_opus_h264.mkv", !ms_file_player_matroska_supported(), TRUE, 15000);
play_file("./sounds/hello_opus_h264.mkv", !ms_media_player_matroska_supported(), TRUE, 15000);
}
static test_t tests[] = {
......
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