<commit_before>/**
 * FreeRDP: A Remote Desktop Protocol client.
 * Xrdp video redirection channel
 *
 * Copyright 2012 <NAME> <<EMAIL>>
 * Copyright 2013 <NAME> <<EMAIL>>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <stdio.h>
#include <stdint.h>
#include <unistd.h>

#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>

/*
centos 5.8
package qffmpeg-devel
/usr/include/qffmpeg/libqavcodec
#define LIBQAVCODEC_VERSION_MAJOR 51
#define LIBQAVCODEC_VERSION_MINOR 71
#define LIBQAVCODEC_VERSION_MICRO  0

debian 6
#define LIBAVCODEC_VERSION_MAJOR 52
#define LIBAVCODEC_VERSION_MINOR 20
#define LIBAVCODEC_VERSION_MICRO  1

debian 7
#define LIBAVCODEC_VERSION_MAJOR 54
#define LIBAVCODEC_VERSION_MINOR 59
#define LIBAVCODEC_VERSION_MICRO 100

ubuntu 10.04
#define LIBAVCODEC_VERSION_MAJOR 52
#define LIBAVCODEC_VERSION_MINOR 20
#define LIBAVCODEC_VERSION_MICRO  1

ubuntu 10.10
#define LIBAVCODEC_VERSION_MAJOR 52
#define LIBAVCODEC_VERSION_MINOR 72
#define LIBAVCODEC_VERSION_MICRO  2

ubuntu 11.04
#define LIBAVCODEC_VERSION_MAJOR 52
#define LIBAVCODEC_VERSION_MINOR 72
#define LIBAVCODEC_VERSION_MICRO  2

ubuntu 11.11
#define LIBAVCODEC_VERSION_MAJOR 53
#define LIBAVCODEC_VERSION_MINOR 34
#define LIBAVCODEC_VERSION_MICRO  0

mint 13, ubuntu 12.04
#define LIBAVCODEC_VERSION_MAJOR 53
#define LIBAVCODEC_VERSION_MINOR 35
#define LIBAVCODEC_VERSION_MICRO  0

*/

#if LIBAVCODEC_VERSION_MAJOR == 52 && LIBAVCODEC_VERSION_MINOR == 20
#define DISTRO_DEBIAN6
#endif

#if LIBAVCODEC_VERSION_MAJOR == 52 && LIBAVCODEC_VERSION_MINOR == 72
#define DISTRO_UBUNTU1104
#endif

#if LIBAVCODEC_VERSION_MAJOR == 53 && LIBAVCODEC_VERSION_MINOR == 34
#define DISTRO_UBUNTU1111
#endif

#if LIBAVCODEC_VERSION_MAJOR == 53 && LIBAVCODEC_VERSION_MINOR == 35
#define DISTRO_UBUNTU1204
#endif

#if LIBAVCODEC_VERSION_MAJOR == 54 && LIBAVCODEC_VERSION_MINOR == 59
#define DISTRO_DEBIAN7
#endif

#if !defined(DISTRO_DEBIAN6) && !defined(DISTRO_UBUNTU1104) && \
    !defined(DISTRO_UBUNTU1111) && !defined(DISTRO_UBUNTU1204) && \
    !defined(DISTRO_DEBIAN7)
#warning unsupported distro
#endif

//#include <freerdp/constants.h>
#include <freerdp/types.h>
#include <freerdp/utils/memory.h>
#include <freerdp/utils/stream.h>
#include <freerdp/utils/list.h>
#include <freerdp/utils/load_plugin.h>
#include <freerdp/utils/svc_plugin.h>
#include <freerdp/utils/event.h>
#include <freerdp/plugins/tsmf.h>

#include "xrdpvr_player.h"
//#include "multiformatdecoder.h"

typedef struct player_state_info
{
	AVFormatContext *format_ctx;
	AVCodecContext  *audio_codec_ctx;
	AVCodecContext  *video_codec_ctx;
	AVCodec         *audio_codec;
	AVCodec         *video_codec;
	AVFrame         *audio_frame;
	AVFrame         *video_frame;

	int              audio_stream_index;
	int              video_stream_index;
	uint8_t         *video_decoded_data;
	uint32_t         video_decoded_size;
	uint8_t         *audio_decoded_data;
	uint32_t         audio_decoded_size;
	uint32_t         decoded_size_max;
	void            *plugin;
	int              player_inited;

	int              audio_prepared;
	int              video_prepared;

	int              xpos;
	int              ypos;
	int              width;
	int              height;
	int              volume;

	//void*		 hw_ctx;
	void*            dec;

} PLAYER_STATE_INFO;

/* forward declarations local to this file */
static int play_video(PLAYER_STATE_INFO *psi, struct AVPacket *av_pkt);
static int play_audio(PLAYER_STATE_INFO *psi, AVPacket *av_pkt);
static uint8_t *get_decoded_video_data(PLAYER_STATE_INFO *psi, uint32_t *size);
static int get_decoded_video_dimension(PLAYER_STATE_INFO *psi, uint32_t *width, uint32_t *height);
static uint32_t get_decoded_video_format(PLAYER_STATE_INFO *psi);
static int display_picture(PLAYER_STATE_INFO *psi);

#if defined(DISTRO_UBUNTU1204) || defined(DISTRO_UBUNTU1111) || defined(DISTRO_DEBIAN7)
#define CODEC_TYPE_VIDEO AVMEDIA_TYPE_VIDEO
#define CODEC_TYPE_AUDIO AVMEDIA_TYPE_AUDIO
#endif

#if defined(DISTRO_DEBIAN7)
#define SAMPLE_FMT_U8 AV_SAMPLE_FMT_U8
#endif

void* init_context(int codec_id);
void destroy_cts(void*ctx);
int decode_video(void*ctx, int* got_frame, unsigned char* data, int size);
int get_output_frame(void*ctx, unsigned char* data, int size);
int get_decoded_size(void*ctx);
void get_decodec_dimentions(void*ctx,int* width,int* height);

/**
 ******************************************************************************/
void* init_player(void* plugin, char* filename)<commit_msg>xrdpvr: ubuntu 14.04 build fix<commit_after>/**
 * FreeRDP: A Remote Desktop Protocol client.
 * Xrdp video redirection channel
 *
 * Copyright 2012 <NAME> <<EMAIL>>
 * Copyright 2013-2014 <NAME> <<EMAIL>>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <stdio.h>
#include <stdint.h>
#include <unistd.h>

#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>

/*
centos 5.8
package qffmpeg-devel
/usr/include/qffmpeg/libqavcodec
#define LIBQAVCODEC_VERSION_MAJOR 51
#define LIBQAVCODEC_VERSION_MINOR 71
#define LIBQAVCODEC_VERSION_MICRO  0

debian 6
#define LIBAVCODEC_VERSION_MAJOR 52
#define LIBAVCODEC_VERSION_MINOR 20
#define LIBAVCODEC_VERSION_MICRO  1

ubuntu 10.04
#define LIBAVCODEC_VERSION_MAJOR 52
#define LIBAVCODEC_VERSION_MINOR 20
#define LIBAVCODEC_VERSION_MICRO  1

ubuntu 10.10
#define LIBAVCODEC_VERSION_MAJOR 52
#define LIBAVCODEC_VERSION_MINOR 72
#define LIBAVCODEC_VERSION_MICRO  2

ubuntu 11.04
#define LIBAVCODEC_VERSION_MAJOR 52
#define LIBAVCODEC_VERSION_MINOR 72
#define LIBAVCODEC_VERSION_MICRO  2

ubuntu 11.11
#define LIBAVCODEC_VERSION_MAJOR 53
#define LIBAVCODEC_VERSION_MINOR 34
#define LIBAVCODEC_VERSION_MICRO  0

mint 13, ubuntu 12.04
#define LIBAVCODEC_VERSION_MAJOR 53
#define LIBAVCODEC_VERSION_MINOR 35
#define LIBAVCODEC_VERSION_MICRO  0

ubuntu 14.04
#define LIBAVCODEC_VERSION_MAJOR 54
#define LIBAVCODEC_VERSION_MINOR 35
#define LIBAVCODEC_VERSION_MICRO  0

debian 7
#define LIBAVCODEC_VERSION_MAJOR 54
#define LIBAVCODEC_VERSION_MINOR 59
#define LIBAVCODEC_VERSION_MICRO 100

*/

#if LIBAVCODEC_VERSION_MAJOR == 52 && LIBAVCODEC_VERSION_MINOR == 20
#define DISTRO_DEBIAN6
#endif

#if LIBAVCODEC_VERSION_MAJOR == 52 && LIBAVCODEC_VERSION_MINOR == 72
#define DISTRO_UBUNTU1104
#endif

#if LIBAVCODEC_VERSION_MAJOR == 53 && LIBAVCODEC_VERSION_MINOR == 34
#define DISTRO_UBUNTU1111
#endif

#if LIBAVCODEC_VERSION_MAJOR == 53 && LIBAVCODEC_VERSION_MINOR == 35
#define DISTRO_UBUNTU1204
#endif

#if LIBAVCODEC_VERSION_MAJOR == 54 && LIBAVCODEC_VERSION_MINOR == 59
#define DISTRO_DEBIAN7
#endif

#if LIBAVCODEC_VERSION_MAJOR == 54 && LIBAVCODEC_VERSION_MINOR == 35
#define DISTRO_UBUNTU1404
#endif


#if !defined(DISTRO_DEBIAN6) && !defined(DISTRO_UBUNTU1104) && \
    !defined(DISTRO_UBUNTU1111) && !defined(DISTRO_UBUNTU1204) && \
    !defined(DISTRO_DEBIAN7) && !defined(DISTRO_UBUNTU1404)
#warning unsupported distro
#endif

//#include <freerdp/constants.h>
#include <freerdp/types.h>
#include <freerdp/utils/memory.h>
#include <freerdp/utils/stream.h>
#include <freerdp/utils/list.h>
#include <freerdp/utils/load_plugin.h>
#include <freerdp/utils/svc_plugin.h>
#include <freerdp/utils/event.h>
#include <freerdp/plugins/tsmf.h>

#include "xrdpvr_player.h"
//#include "multiformatdecoder.h"

typedef struct player_state_info
{
	AVFormatContext *format_ctx;
	AVCodecContext  *audio_codec_ctx;
	AVCodecContext  *video_codec_ctx;
	AVCodec         *audio_codec;
	AVCodec         *video_codec;
	AVFrame         *audio_frame;
	AVFrame         *video_frame;

	int              audio_stream_index;
	int              video_stream_index;
	uint8_t         *video_decoded_data;
	uint32_t         video_decoded_size;
	uint8_t         *audio_decoded_data;
	uint32_t         audio_decoded_size;
	uint32_t         decoded_size_max;
	void            *plugin;
	int              player_inited;

	int              audio_prepared;
	int              video_prepared;

	int              xpos;
	int              ypos;
	int              width;
	int              height;
	int              volume;

	//void*		 hw_ctx;
	void*            dec;

} PLAYER_STATE_INFO;

/* forward declarations local to this file */
static int play_video(PLAYER_STATE_INFO *psi, struct AVPacket *av_pkt);
static int play_audio(PLAYER_STATE_INFO *psi, AVPacket *av_pkt);
static uint8_t *get_decoded_video_data(PLAYER_STATE_INFO *psi, uint32_t *size);
static int get_decoded_video_dimension(PLAYER_STATE_INFO *psi, uint32_t *width, uint32_t *height);
static uint32_t get_decoded_video_format(PLAYER_STATE_INFO *psi);
static int display_picture(PLAYER_STATE_INFO *psi);

#if defined(DISTRO_UBUNTU1204) || defined(DISTRO_UBUNTU1111) || defined(DISTRO_DEBIAN7) || defined(DISTRO_UBUNTU1404)
#define CODEC_TYPE_VIDEO AVMEDIA_TYPE_VIDEO
#define CODEC_TYPE_AUDIO AVMEDIA_TYPE_AUDIO
#endif

#if defined(DISTRO_DEBIAN7) || defined(DISTRO_UBUNTU1404)
#define SAMPLE_FMT_U8 AV_SAMPLE_FMT_U8
#endif

void* init_context(int codec_id);
void destroy_cts(void*ctx);
int decode_video(void*ctx, int* got_frame, unsigned char* data, int size);
int get_output_frame(void*ctx, unsigned char* data, int size);
int get_decoded_size(void*ctx);
void get_decodec_dimentions(void*ctx,int* width,int* height);

/**
 ******************************************************************************/
void* init_player(void* plugin, char* filename)
{'fraction_non_alphanumeric': 0.09681787406905891, 'fraction_numerical': 0.03394912467356611, 'mean_word_length': 4.881683731513083, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1054993', 'n_tokens_mistral': 4105, 'n_tokens_neox': 3689, 'n_words': 857}