//
// avplayer.h
// ~~~~~~~~~~
//
// Copyright (c) 2011 Jack (jack.wgm@gmail.com)
//

#ifndef __AVPLAYER_H__
#define __AVPLAYER_H__

#ifdef API_EXPORTS
#define EXPORT_API __declspec(dllexport)
#else
#define EXPORT_API __declspec(dllimport)
#endif

#pragma once

// 鎵撳紑濯掍綋绫诲瀷.
#define MEDIA_TYPE_FILE	0
#define MEDIA_TYPE_BT	1
#define MEDIA_TYPE_HTTP 2
#define MEDIA_TYPE_RTSP 3
#define MEDIA_TYPE_YK	4

// 娓叉煋妯″紡.
#define RENDER_DDRAW	0
#define RENDER_D3D		1
#define RENDER_OGL		2
#define RENDER_SOFT		3
#define RENDER_Y4M		4

class player_impl;
// avplayer灏佽绫?
class EXPORT_API avplayer
{
public:
	avplayer(void);
	~avplayer(void);

public:
	// 鍒涘缓绐楀彛, 涔熷彲浠ヤ娇鐢╯ubclasswindow闄勫姞鍒颁竴涓寚瀹氱殑绐楀彛.
	HWND create_window(const char *player_name);

	// 閿€姣佺獥鍙? 鍙兘鎾ら攢鏄敱create_window鍒涘缓鐨勭獥鍙?
	BOOL destory_window();

	// 瀛愮被鍖栦竴涓瓨鍦ㄧ殑绐楀彛, in_process鍙傛暟琛ㄧず绐楀彛鏄惁鍦ㄥ悓涓€杩涚▼涓?
	BOOL subclasswindow(HWND hwnd, BOOL in_process = TRUE);

	// 鎾ゆ秷瀛愮被鍖?
	BOOL unsubclasswindow(HWND hwnd);

public:
	// 鎵撳紑涓€涓獟浣撴枃浠?	// movie 鏂囦欢鍚?
	// media_type 琛ㄧず鎵撳紑鐨勫獟浣撶被鍨?
	// render_type 琛ㄧず鎾斁娓叉煋妯″紡, 榛樿鏄痙draw娓叉煋.
	// 娉ㄦ剰, 杩欎釜鍑芥暟鍙墦寮€鏂囦欢, 浣嗗苟涓嶆挱鏀? 閲嶆柊鎵撳紑鏂囦欢鍓? 蹇?	// 椤诲叧闂箣鍓嶇殑濯掍綋鏂囦欢, 鍚﹀垯鍙兘浜х敓鍐呭瓨娉勬紡! 鍙﹀, 鍦ㄦ挱鏀?	// 鍓? avplayer蹇呴』鎷ユ湁涓€涓獥鍙?
	BOOL open(const char *movie, int media_type, int render_type = RENDER_D3D);

	// 寮€濮嬫挱鏀捐棰?
	// fact 琛ㄧず鎾斁瑙嗛鐨勮捣濮嬩綅缃? 鎸夎棰戠櫨鍒嗘瘮璁$畻, 榛樿浠庢枃浠跺ご寮€濮嬫挱鏀?
	// index 鎾斁绱㈠紩涓篿ndex鐨勬枃浠? index琛ㄧず鍦ㄦ挱鏀惧垪琛ㄤ腑鐨勪綅缃鏁? 浠?寮€濮嬭
	// 绠? index涓昏鐢ㄤ簬鎾斁澶氭枃浠剁殑bt鏂囦欢, 鍗曚釜鏂囦欢鎾斁鍙互浣跨敤鐩存帴榛樿涓?鑰屼笉
	// 闇€瑕佸~鍐欏弬鏁?
	BOOL play(double fact = 0.0f, int index = 0);

	// 鍔犺浇瀛楀箷.
	BOOL load_subtitle(const char *subtitle);

	// 鏆傚仠鎾斁.
	BOOL pause();

	// 缁х画鎾斁.
	BOOL resume();

	// 鍋滄鎾斁.
	BOOL stop();

	// 绛夊緟鎾斁鐩村埌瀹屾垚.
	BOOL wait_for_completion();

	// 鍏抽棴濯掍綋, 濡傛灉鎵撳紑鐨勬槸涓€涓猙t鏂囦欢, 閭d箞
	// 鍦ㄨ繖涓猙t鏂囦欢涓殑鎵€鏈夎棰戞枃浠跺皢琚叧闂?
	BOOL close();

	// seek鍒版煇涓椂闂存挱鏀? 鎸夎棰戞椂闀跨殑鐧惧垎姣?
	void seek_to(double fact);

	// 璁剧疆澹伴煶闊抽噺澶у皬.
	void volume(double l, double r);

	// 闈欓煶璁剧疆.
	void mute_set(bool s);

	// 鍏ㄥ睆鍒囨崲.
	// 娉ㄦ剰: 涓嶆敮鎸侀潪椤跺眰绐楀彛鍏ㄥ睆鎿嶄綔!
	BOOL full_screen(BOOL fullscreen);

	// 褰撳墠涓嬭浇閫熺巼, 鍗曚綅kB/s.
	int download_rate();

	// 闄愬埗涓嬭浇閫熺巼.
	void set_download_rate(int k);

	// 杩斿洖褰撳墠鎾斁鏃堕棿.
	double curr_play_time();

	// 褰撳墠鎾斁瑙嗛鐨勬椂闀? 鍗曚綅绉?
	double duration();

	// 褰撳墠鎾斁瑙嗛鐨勯珮, 鍗曚綅鍍忕礌.
	int video_width();

	// 褰撳墠鎾斁瑙嗛鐨勫, 鍗曚綅鍍忕礌.
	int video_height();

	// 褰撳墠缂撳啿杩涘害, 鍗曚綅鐧惧垎姣?
	double buffering();

	// 杩斿洖褰撳墠鎾斁鍒楄〃涓殑濯掍綋鏂囦欢鏁?
	int media_count();

	// 杩斿洖鎾斁鍒楄〃.
	// 鍙傛暟list鍦ㄦā鍧楀唴鍒嗛厤鍐呭瓨, 閫氳繃size鍙傛暟浼犲嚭鍒楄〃澶у皬.
	// @ example begin
	//   char **list;
	//   int size = 0;
	//   play->media_list(&list, &size);
	//   ...
	//   play->free_media_list(list, size);
	// @ example end
	int media_list(char ***list, int* size);

	// 閲婃斁鎾斁鍒楄〃鐨勫垎閰嶇殑鍐呭瓨璧勬簮.
	void free_media_list(char **list, int size);

	// 杩斿洖褰撳墠绐楀彛鍙ユ焺.
	HWND get_window_handle();

private:
	player_impl *m_impl;
};

#endif // __AVPLAYER_H__