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

Add comments to the MSFilePlayer API

parent 895c19ed
#ifndef FILEPLAYER_H
#define FILEPLAYER_H
#include "mscommon.h"
#include "mssndcard.h"
#include "msinterfaces.h"
typedef struct _FilePlayer FilePlayer;
/**
* @brief Media file player
*/
typedef struct _MSFilePlayer MSFilePlayer;
typedef void (*FilePlayerEofCallback)(void *user_data);
typedef void (*MSFilePlayerEofCallback)(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);
/**
* @brief Instanciate a file player
* @param snd_card Playback sound card
* @param video_display_name Video out
* @return A pointer on the created MSFilePlayer
*/
MS2_PUBLIC MSFilePlayer *ms_file_player_new(MSSndCard *snd_card, const char *video_display_name);
/**
* @brief Free a file player
* @param obj Pointer on the MSFilePlayer to free
*/
MS2_PUBLIC void ms_file_player_free(MSFilePlayer *obj);
/**
* @brief Set the "End of File" callback
* @param obj A MSFilePlayer object pointer
* @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);
/**
* @brief Open a media file
* @param obj A pointer on a MSFilePlayer
* @param filepath Path of the file to open
* @return TRUE if the file could be opened
*/
bool_t ms_file_player_open(MSFilePlayer *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);
/**
* @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);
/**
* @brief Stop a playback
* When a playback is stoped, the player automatically seek at
* the begining of the file.
* @param obj A pointer on a MSFilePlayer
*/
MS2_PUBLIC void ms_file_player_stop(MSFilePlayer *obj);
/**
* @brief Turn playback to paused.
* @param obj A pointer on a MSFilePlayer
*/
MS2_PUBLIC void ms_file_player_pause(MSFilePlayer *obj);
/**
* @brief Seek into the opened file
* Can be safly call when playback is runing
* @param obj A pointer on a MSFilePlayer
* @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);
/**
* @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);
#endif
......@@ -37,7 +37,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 _FilePlayer {
struct _MSFilePlayer {
MSFilter *player;
MSFilter *audio_decoder;
MSFilter *audio_sink;
......@@ -50,7 +50,7 @@ struct _FilePlayer {
FileFormat format;
bool_t is_open;
char *filename;
FilePlayerEofCallback eof_cb;
MSFilePlayerEofCallback eof_cb;
void *user_data_cb;
ms_mutex_t cb_access;
MSSndCard *snd_card;
......@@ -59,11 +59,11 @@ struct _FilePlayer {
static bool_t _get_format(const char *filepath, FileFormat *format);
static void _eof_filter_notify_cb(void *userdata, struct _MSFilter *f, unsigned int id, void *arg);
static void _create_decoders(FilePlayer *obj);
static void _create_sinks(FilePlayer *obj);
static void _destroy_graph(FilePlayer *obj);
static bool_t _link_all(FilePlayer *obj);
static void _unlink_all(FilePlayer *obj);
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 bool_t four_cc_compare(const FourCC arg1, const FourCC arg2) {
return arg1[0] == arg2[0]
......@@ -82,8 +82,8 @@ static FileFormat four_cc_to_file_format(const FourCC four_cc) {
return FILE_FORMAT_UNKNOWN;
}
FilePlayer *ms_file_player_new(MSSndCard *snd_card, const char *video_display_name) {
FilePlayer *obj = (FilePlayer *)ms_new0(FilePlayer, 1);
MSFilePlayer *ms_file_player_new(MSSndCard *snd_card, const char *video_display_name) {
MSFilePlayer *obj = (MSFilePlayer *)ms_new0(MSFilePlayer, 1);
obj->ticker = ms_ticker_new();
ms_mutex_init(&obj->cb_access, NULL);
obj->snd_card = snd_card;
......@@ -93,13 +93,13 @@ FilePlayer *ms_file_player_new(MSSndCard *snd_card, const char *video_display_na
return obj;
}
void ms_file_player_free(FilePlayer *obj) {
void ms_file_player_free(MSFilePlayer *obj) {
ms_file_player_close(obj);
ms_ticker_destroy(obj->ticker);
ms_free_if_not_null(obj->video_display);
}
bool_t ms_file_player_open(FilePlayer *obj, const char *filepath) {
bool_t ms_file_player_open(MSFilePlayer *obj, const char *filepath) {
wave_header_t header;
int fd;
char *tmp;
......@@ -162,7 +162,7 @@ bool_t ms_file_player_open(FilePlayer *obj, const char *filepath) {
return TRUE;
}
void ms_file_player_close(FilePlayer *obj) {
void ms_file_player_close(MSFilePlayer *obj) {
if(obj->is_open) {
ms_ticker_detach(obj->ticker, obj->player);
ms_filter_call_method_noarg(obj->player, MS_PLAYER_CLOSE);
......@@ -173,7 +173,7 @@ void ms_file_player_close(FilePlayer *obj) {
}
}
bool_t ms_file_player_start(FilePlayer *obj) {
bool_t ms_file_player_start(MSFilePlayer *obj) {
if(!obj->is_open) {
ms_error("Cannot start playing. No file has been opened");
return FALSE;
......@@ -185,7 +185,7 @@ bool_t ms_file_player_start(FilePlayer *obj) {
return TRUE;
}
void ms_file_player_stop(FilePlayer *obj) {
void ms_file_player_stop(MSFilePlayer *obj) {
int seek_pos = 0;
if(obj->is_open) {
ms_filter_call_method_noarg(obj->player, MS_PLAYER_PAUSE);
......@@ -193,19 +193,29 @@ void ms_file_player_stop(FilePlayer *obj) {
}
}
void ms_file_player_pause(FilePlayer *obj) {
void ms_file_player_pause(MSFilePlayer *obj) {
if(obj->is_open) {
ms_filter_call_method_noarg(obj->player, MS_PLAYER_PAUSE);
}
}
void ms_file_player_seek(FilePlayer *obj, int seek_pos_ms) {
bool_t ms_file_player_seek(MSFilePlayer *obj, int seek_pos_ms) {
if(obj->is_open) {
ms_filter_call_method(obj->player, MS_PLAYER_SEEK_MS, &seek_pos_ms);
return ms_filter_call_method(obj->player, MS_PLAYER_SEEK_MS, &seek_pos_ms) == 0 ? TRUE : FALSE;
}
}
void ms_file_player_set_eof_callback(FilePlayer *obj, FilePlayerEofCallback cb, void *user_data) {
MSPlayerState ms_file_player_get_state(MSFilePlayer *obj) {
if(obj->is_open) {
MSPlayerState state;
ms_filter_call_method(obj->player, MS_PLAYER_GET_STATE, &state);
return state;
} else {
return MS_PLAYER_CLOSE;
}
}
void ms_file_player_set_eof_callback(MSFilePlayer *obj, MSFilePlayerEofCallback cb, void *user_data) {
ms_mutex_lock(&obj->cb_access);
obj->eof_cb = cb;
obj->user_data_cb = user_data;
......@@ -231,7 +241,7 @@ static bool_t _get_format(const char *filepath, FileFormat *format) {
return TRUE;
}
static void _create_decoders(FilePlayer *obj) {
static void _create_decoders(MSFilePlayer *obj) {
int sample_rate, nchannels;
switch(obj->format) {
case FILE_FORMAT_WAVE:
......@@ -269,7 +279,7 @@ static void _create_decoders(FilePlayer *obj) {
}
}
static void _create_sinks(FilePlayer *obj) {
static void _create_sinks(MSFilePlayer *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;
......@@ -302,7 +312,7 @@ static void _create_sinks(FilePlayer *obj) {
}
}
static void _destroy_graph(FilePlayer *obj) {
static void _destroy_graph(MSFilePlayer *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);
......@@ -313,7 +323,7 @@ static void _destroy_graph(FilePlayer *obj) {
obj->video_pin_fmt.fmt = NULL;
}
static bool_t _link_all(FilePlayer *obj) {
static bool_t _link_all(MSFilePlayer *obj) {
MSConnectionHelper helper;
if(obj->player == NULL) {
ms_error("Could not link graph. There is no playing filter");
......@@ -339,7 +349,7 @@ static bool_t _link_all(FilePlayer *obj) {
return TRUE;
}
static void _unlink_all(FilePlayer *obj) {
static void _unlink_all(MSFilePlayer *obj) {
MSConnectionHelper helper;
if(obj->audio_pin_fmt.fmt && obj->audio_sink) {
ms_connection_helper_start(&helper);
......@@ -357,7 +367,7 @@ static void _unlink_all(FilePlayer *obj) {
}
static void _eof_filter_notify_cb(void *userdata, struct _MSFilter *f, unsigned int id, void *arg) {
FilePlayer *obj = (FilePlayer *)userdata;
MSFilePlayer *obj = (MSFilePlayer *)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);
......
......@@ -44,7 +44,7 @@ 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 succeed;
Eof eof;
FilePlayer *file_player = NULL;
MSFilePlayer *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();
......
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