o development checkin

o added vrplayer
This commit is contained in:
Laxmikant Rashinkar
2012-12-08 16:36:41 -08:00
parent 309f2225b1
commit 4c67aad4c4
13 changed files with 1063 additions and 60 deletions
+107 -41
View File
@@ -25,6 +25,8 @@
/* globals */
PLAYER_STATE_INFO g_psi;
int g_video_index = -1;
int g_audio_index = -1;
/**
* initialize the media player
@@ -129,10 +131,6 @@ xrdpvr_deinit_player(void *channel, int stream_id)
int
xrdpvr_play_media(void *channel, int stream_id, char *filename)
{
AVPacket av_pkt;
int video_index = -1;
int audio_index = -1;
int i;
/* register all available fileformats and codecs */
@@ -161,19 +159,19 @@ xrdpvr_play_media(void *channel, int stream_id, char *filename)
for (i = 0; i < g_psi.p_format_ctx->nb_streams; i++)
{
if (g_psi.p_format_ctx->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO &&
video_index < 0)
g_video_index < 0)
{
video_index = i;
g_video_index = i;
}
if (g_psi.p_format_ctx->streams[i]->codec->codec_type == AVMEDIA_TYPE_AUDIO &&
audio_index < 0)
g_audio_index < 0)
{
audio_index = i;
g_audio_index = i;
}
}
if ((audio_index < 0) && (video_index < 0))
if ((g_audio_index < 0) && (g_video_index < 0))
{
/* close file and return with error */
printf("ERROR: no audio/video stream found in %s\n", filename);
@@ -181,12 +179,12 @@ xrdpvr_play_media(void *channel, int stream_id, char *filename)
return -1;
}
g_psi.audio_stream_index = audio_index;
g_psi.video_stream_index = video_index;
g_psi.audio_stream_index = g_audio_index;
g_psi.video_stream_index = g_video_index;
/* get pointers to codex contexts for both streams */
g_psi.p_audio_codec_ctx = g_psi.p_format_ctx->streams[audio_index]->codec;
g_psi.p_video_codec_ctx = g_psi.p_format_ctx->streams[video_index]->codec;
g_psi.p_audio_codec_ctx = g_psi.p_format_ctx->streams[g_audio_index]->codec;
g_psi.p_video_codec_ctx = g_psi.p_format_ctx->streams[g_video_index]->codec;
/* find decoder for audio stream */
g_psi.p_audio_codec = avcodec_find_decoder(g_psi.p_audio_codec_ctx->codec_id);
@@ -220,32 +218,99 @@ xrdpvr_play_media(void *channel, int stream_id, char *filename)
return -1;
}
while (av_read_frame(g_psi.p_format_ctx, &av_pkt) >= 0)
{
if (av_pkt.stream_index == audio_index)
{
xrdpvr_send_audio_data(channel, stream_id, av_pkt.size, av_pkt.data);
usleep(1000 * 1);
}
else if (av_pkt.stream_index == video_index)
{
xrdpvr_send_video_data(channel, stream_id, av_pkt.size, av_pkt.data);
usleep(1000 * 40); // was 50
}
}
av_free_packet(&av_pkt);
return 0;
}
/******************************************************************************
*
* code below this is local to this file and cannot be accessed externally;
* this code communicates with the xrdpvr plugin in NeutrinoRDP;
* NeutrinoRDP is a fork of FreeRDP 1.0.1
*
*****************************************************************************/
int xrdpvr_play_frame(void *channel, int stream_id)
{
AVPacket av_pkt;
printf("xrdpvr_play_frame: entered\n");
if (av_read_frame(g_psi.p_format_ctx, &av_pkt) < 0)
{
printf("xrdpvr_play_frame: av_read_frame failed\n");
return -1;
}
if (av_pkt.stream_index == g_audio_index)
{
xrdpvr_send_audio_data(channel, stream_id, av_pkt.size, av_pkt.data);
usleep(1000 * 1);
}
else if (av_pkt.stream_index == g_video_index)
{
xrdpvr_send_video_data(channel, stream_id, av_pkt.size, av_pkt.data);
usleep(1000 * 40); // was 50
}
av_free_packet(&av_pkt);
return 0;
}
int
xrdpvr_seek_media(int64_t pos, int backward)
{
int64_t seek_target;
int seek_flag;
printf("xrdpvr_seek_media() entered\n");
seek_flag = (backward) ? AVSEEK_FLAG_BACKWARD : 0;
seek_target = av_rescale_q(pos * AV_TIME_BASE,
AV_TIME_BASE_Q,
g_psi.p_format_ctx->streams[g_video_index]->time_base);
if(av_seek_frame(g_psi.p_format_ctx, g_video_index, seek_target, seek_flag) < 0)
{
printf("media seek error\n");
return -1;
}
printf("xrdpvr_seek_media: success\n");
return 0;
}
void
xrdpvr_get_media_duration(int64_t *start_time, int64_t *duration)
{
*start_time = g_psi.p_format_ctx->start_time / AV_TIME_BASE;
*duration = g_psi.p_format_ctx->duration / AV_TIME_BASE;
}
int
xrdpvr_set_geometry(void *channel, int stream_id, int xpos, int ypos, int width, int height)
{
STREAM *s;
char *cptr;
int rv;
int len;
printf("xrdpvr_set_geometry: entered; x=%d y=%d\n", xpos, ypos);
stream_new(s, MAX_PDU_SIZE);
stream_ins_u32_le(s, 0); /* number of bytes to follow */
stream_ins_u32_le(s, CMD_SET_GEOMETRY);
stream_ins_u32_le(s, stream_id);
stream_ins_u32_le(s, xpos);
stream_ins_u32_le(s, ypos);
stream_ins_u32_le(s, width);
stream_ins_u32_le(s, height);
/* insert number of bytes in stream */
len = stream_length(s) - 4;
cptr = s->p;
s->p = s->data;
stream_ins_u32_le(s, len);
s->p = cptr;
/* write data to virtual channel */
rv = xrdpvr_write_to_client(channel, s);
stream_free(s);
return rv;
}
/**
* set video format
@@ -255,7 +320,7 @@ xrdpvr_play_media(void *channel, int stream_id, char *filename)
*
* @return 0 on success, -1 on error
*****************************************************************************/
static int
int
xrdpvr_set_video_format(void *channel, uint32_t stream_id)
{
STREAM *s;
@@ -290,7 +355,7 @@ xrdpvr_set_video_format(void *channel, uint32_t stream_id)
*
* @return 0 on success, -1 on error
*****************************************************************************/
static int
int
xrdpvr_set_audio_format(void *channel, uint32_t stream_id)
{
STREAM *s;
@@ -327,7 +392,7 @@ xrdpvr_set_audio_format(void *channel, uint32_t stream_id)
*
* @return 0 on success, -1 on error
*****************************************************************************/
static int
int
xrdpvr_send_video_data(void *channel, uint32_t stream_id, uint32_t data_len, uint8_t *data)
{
STREAM *s;
@@ -371,7 +436,7 @@ xrdpvr_send_video_data(void *channel, uint32_t stream_id, uint32_t data_len, uin
*
* @return 0 on success, -1 on error
*****************************************************************************/
static int
int
xrdpvr_send_audio_data(void *channel, uint32_t stream_id, uint32_t data_len, uint8_t *data)
{
STREAM *s;
@@ -408,7 +473,7 @@ xrdpvr_send_audio_data(void *channel, uint32_t stream_id, uint32_t data_len, uin
*
* @return 0 on success, -1 on error
*****************************************************************************/
static int
int
xrdpvr_create_metadata_file(void *channel, char *filename)
{
STREAM *s;
@@ -518,3 +583,4 @@ xrdpvr_write_to_client(void *channel, STREAM *s)
usleep(1000 * 3);
}
}
+14 -3
View File
@@ -23,13 +23,24 @@
#ifndef __XRDPVR_H__
#define __XRDPVR_H__
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
int xrdpvr_init_player(void *channel, int stream_id, char *filename);
int xrdpvr_deinit_player(void *channel, int stream_id);
int xrdpvr_play_media(void *channel, int stream_id, char *filename);
int xrdpvr_init_player(void *channel, int stream_id, char *filename);
int xrdpvr_deinit_player(void *channel, int stream_id);
int xrdpvr_play_media(void *channel, int stream_id, char *filename);
int xrdpvr_set_geometry(void *channel, int stream_id, int xpos, int ypos, int width, int height);
int xrdpvr_set_video_format(void *channel, uint32_t stream_id);
int xrdpvr_set_audio_format(void *channel, uint32_t stream_id);
int xrdpvr_send_video_data(void *channel, uint32_t stream_id, uint32_t data_len, uint8_t *data);
int xrdpvr_send_audio_data(void *channel, uint32_t stream_id, uint32_t data_len, uint8_t *data);
int xrdpvr_create_metadata_file(void *channel, char *filename);
int xrdpvr_play_frame(void *channel, int stream_id);
void xrdpvr_get_media_duration(int64_t *start_time, int64_t *duration);
int xrdpvr_seek_media(int64_t pos, int backward);
#ifdef __cplusplus
}
+12 -16
View File
@@ -38,6 +38,7 @@
#define CMD_CLOSE_META_DATA_FILE 6
#define CMD_WRITE_META_DATA 7
#define CMD_DEINIT_XRDPVR 8
#define CMD_SET_GEOMETRY 9
/* max number of bytes we can send in one pkt */
#define MAX_PDU_SIZE 1600
@@ -60,7 +61,7 @@ typedef struct stream
* @param _s stream to create and init
* @param _len number of bytes to store in stream
******************************************************************************/
#define stream_new(_s, _len) \
#define stream_new(_s, _len) \
do \
{ \
(_s) = (STREAM *) calloc(1, sizeof(STREAM)); \
@@ -73,7 +74,7 @@ typedef struct stream
/**
* create a stream from an existing buffer
******************************************************************************/
#define stream_from_buffer(_s, _buf, _buf_len) \
#define stream_from_buffer(_s, _buf, _buf_len) \
do \
{ \
(_s) = (STREAM *) calloc(1, sizeof(STREAM)); \
@@ -89,7 +90,7 @@ typedef struct stream
*
* @param _s the stream whose resources are to be released
******************************************************************************/
#define stream_free(_s) \
#define stream_free(_s) \
do \
{ \
if (!(_s)->from_buf) \
@@ -104,14 +105,14 @@ typedef struct stream
#define stream_length(_s) (int) ((_s)->p - (_s)->data)
/** insert a 8 bit value into stream */
#define stream_ins_u8(_s, _val) \
#define stream_ins_u8(_s, _val) \
do \
{ \
*(_s)->p++ = (unsigned char) (_val); \
} while(0)
/** insert a 16 bit value into stream */
#define stream_ins_u16_le(_s, _val) \
#define stream_ins_u16_le(_s, _val) \
do \
{ \
*(_s)->p++ = (unsigned char) ((_val) >> 0); \
@@ -119,7 +120,7 @@ typedef struct stream
} while (0)
/** insert a 32 bit value into stream */
#define stream_ins_u32_le(_s, _val) \
#define stream_ins_u32_le(_s, _val) \
do \
{ \
*(_s)->p++ = (unsigned char) ((_val) >> 0); \
@@ -129,7 +130,7 @@ typedef struct stream
} while (0)
/** insert a 64 bit value into stream */
#define stream_ins_u64_le(_s, _val) \
#define stream_ins_u64_le(_s, _val) \
do \
{ \
*(_s)->p++ = (unsigned char) ((_val) >> 0); \
@@ -143,7 +144,7 @@ typedef struct stream
} while (0)
/** insert array of chars into stream */
#define stream_ins_byte_array(_s, _ba, _count) \
#define stream_ins_byte_array(_s, _ba, _count) \
do \
{ \
memcpy((_s)->p, (_ba), (_count)); \
@@ -151,14 +152,14 @@ typedef struct stream
} while (0)
/** extract a 8 bit value from stream */
#define stream_ext_u8(_s, _v) \
#define stream_ext_u8(_s, _v) \
do \
{ \
(_v) = (u8) *(_s)->p++; \
} while (0)
/** extract a 16 bit value from stream */
#define stream_ext_u16_le(_s, _v) \
#define stream_ext_u16_le(_s, _v) \
do \
{ \
(_v) = (u16) ((_s)->p[1] << 8 | (_s)->p[0]); \
@@ -166,7 +167,7 @@ typedef struct stream
} while (0)
/** extract a 32 bit value from stream */
#define stream_ext_u32_le(_s, _v) \
#define stream_ext_u32_le(_s, _v) \
do \
{ \
(_v) = (u32) ((_s)->p[3] << 24 | \
@@ -193,11 +194,6 @@ typedef struct _player_state_info
} PLAYER_STATE_INFO;
static int xrdpvr_set_video_format(void *channel, uint32_t stream_id);
static int xrdpvr_set_audio_format(void *channel, uint32_t stream_id);
static int xrdpvr_send_video_data(void *channel, uint32_t stream_id, uint32_t data_len, uint8_t *data);
static int xrdpvr_send_audio_data(void *channel, uint32_t stream_id, uint32_t data_len, uint8_t *data);
static int xrdpvr_create_metadata_file(void *channel, char *filename);
static int xrdpvr_write_to_client(void *channel, STREAM *s);
#endif /* __XRDPVR_INTERNAL_H__ */