⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 datasource.h

📁 彩信浏览器
💻 H
📖 第 1 页 / 共 2 页
字号:
/* * This file is part of Ambulant Player, www.ambulantplayer.org. * * Copyright (C) 2003-2007 Stichting CWI,  * Kruislaan 413, 1098 SJ Amsterdam, The Netherlands. * * Ambulant Player is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * Ambulant Player 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 Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with Ambulant Player; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */ #ifndef AMBULANT_NET_DATASOURCE_H#define AMBULANT_NET_DATASOURCE_H#include "ambulant/config/config.h"#include "ambulant/lib/callback.h"#include "ambulant/lib/refcount.h"#include "ambulant/lib/event_processor.h"#include "ambulant/lib/thread.h"#include "ambulant/common/playable.h"#include "ambulant/net/url.h"#include "ambulant/net/databuffer.h"#ifdef AMBULANT_PLATFORM_UNIX#include <stdint.h>#include "ambulant/lib/unix/unix_thread.h"#endif#ifdef _MSC_VER#pragma warning(disable : 4251)#endifnamespace ambulant {namespace net {	#ifdef AMBULANT_HAS_LONG_LONG  	typedef long long int timestamp_t; ///< Time value in microseconds.#else	typedef INT64 timestamp_t; ///< Time value in microseconds.#endif	/// This struct completely describes an audio format./// If name is "" the format is linear samples encoded/// in host order, and samplerate, channels and bits/// are meaningful. If name is nonempty it is some encoded/// format, parameters points to format-specific data/// and samplerate/channels/bits are not meaningful.struct audio_format {		std::string mime_type; ///< Mimetype of the format, or "audio/unknown"	std::string name;	///< Name of the format, or empty for linear samples	void *parameters;	///< For a named format, pointer to parameters	int samplerate;		///< For linear samples: the samplerate	int channels;		///< For linear samples: the number of channels	int bits;			///< For linear samples: the numer of bits per sample.		/// Default constructor: creates unknown audio_format.	audio_format()	:   mime_type("audio/unknown"),		name("unknown"),		parameters(NULL),		samplerate(0),		channels(0),		bits(0) {};			/// Constructor for linear samples, pass samplerate, number of channels, bits per sample.	audio_format(int s, int c, int b)	:   mime_type("audio/unknown"),		name(""),		parameters(NULL),		samplerate(s),		channels(c),		bits(b) {};		/// Constructor for named audio_format, optionally pass extra format-dependent info.	audio_format(const std::string &n, void *p=(void *)0)	:   mime_type("audio/unknown"),		name(n),		parameters(p),		samplerate(0),		channels(0),		bits(0) {};			/// Constructor for named audio_format, optionally pass extra format-dependent info.	audio_format(const char *n, void *p=(void *)0)	:   mime_type("audio/unknown"),		name(n),		parameters(p),		samplerate(0),		channels(0),		bits(0) {};};/// This struct completely describes a video format./// If name is "" the format is a sequence of uncompressed images./// Parameters may be 0 if the values are not known.struct video_format {		std::string mime_type;      ///< Mimetype of the format, or "video/unknown"	std::string name;			///< Name of the format	void *parameters;			///< For a named format, pointer to parameters	timestamp_t frameduration;	///< For linear samples: the samplerate	int width;					/// The width of the video	int height;					///	The height of the video		/// Default constructor: creates unknown video_format.	video_format()	:   mime_type("video/unknown"),		name("unknown"),		parameters(NULL),		frameduration(0),		width(0),		height(0) {};			/// Constructor for named video_format.	video_format(std::string &n, void *p=(void *)0)	:   mime_type("video/unknown"),		name(n),		parameters(p),		frameduration(0),		width(0),		height(0) {};			/// Constructor for named video_format.	video_format(const char *n, void *p=(void *)0)	:   mime_type("video/unknown"),		name(n),		parameters(p),		frameduration(0),		width(0),		height(0) {};};#ifdef __OBJC__// This is a workaround for a problem when using gcc 3.3 to compile// ObjC++;#endif// This class describes the range of audio formats supported by a consumer.// It always contains at least one supported format.// The design assumes that support for various sample rates, channels and// bits are independent variables. In addition, an audio_format_choices// can support both various linear formats and named formats.class audio_format_choices {  public:  	/// Default constructor: support no formats.	audio_format_choices();		/// Constructor using a single audio_format.	audio_format_choices(const audio_format &fmt);		/// Constructor using a linear sample format. 	audio_format_choices(int samplerate, int channels, int bits);		/// Constructor using a named format.	audio_format_choices(const std::string &name);		/// Return the best (highest quality) format.	const audio_format& best() const;		/// Add support for an additional samplerate.	void add_samplerate(int samplerate);		/// Add support for an additional number of channels.	void add_channels(int channels);		/// Add support for an addition number of bits per sample.	void add_bits(int bits);		/// Add support for an additional named format.	void add_named_format(const std::string &name);		/// Return true if the audio_format argument matches any of the supported formats.	bool contains(const audio_format& fmt) const;	  private:	audio_format m_best;	std::set<int> m_samplerate;	std::set<int> m_channels;	std::set<int> m_bits;	std::set<std::string> m_named_formats;};struct ts_packet_t { timestamp_t timestamp; void* data; int size; 	ts_packet_t(timestamp_t t, void* d, int s) 	  : timestamp(t), data(d), size(s) {}};/// The interface to an object that supplies data to a consumer./// The consumer calls start() whenever it wants/// data. This call returns immedeately and later the datasource arranges/// that the callback is done, when data is available. The consumer then/// calls size(), get_read_ptr() and end_of_file() to get available data size,/// pointer and status. Whenever the consumer has consumed some bytes it calls/// read_done().class AMBULANTAPI datasource : virtual public ambulant::lib::ref_counted {  	  public:	virtual ~datasource() {};	/// Called by the client to indicate it wants more data.	/// When the data is available (or end of file reached) exactly one	/// callback is scheduled through the event_processor.	virtual void start(ambulant::lib::event_processor *evp, ambulant::lib::event *callback) = 0;		/// Called by the client to indicate it wants no more data.	virtual void stop() = 0;	/// Return true if all data has been consumed.	virtual bool end_of_file() = 0;		/// Return a pointer to the current data.	/// Should only be called from the callback routine.	virtual char* get_read_ptr() = 0;		/// Return the number of bytes available at get_read_ptr().	virtual int size() const = 0;			/// Called by the client to signal it has consumed len bytes.	virtual void readdone(int len) = 0;};class AMBULANTAPI pkt_datasource : virtual public ambulant::lib::ref_counted {  	  public:	virtual ~pkt_datasource() {};	/// Called by the client to indicate it wants more data.	/// When the data is available (or end of file reached) exactly one	/// callback is scheduled through the event_processor.	virtual void start(ambulant::lib::event_processor *evp, ambulant::lib::event *callback) = 0;		/// Called by the client to indicate it wants no more data.	virtual void stop() = 0;	/// Return true if all data has been consumed.	virtual bool end_of_file() = 0;		/// Return the next timestamped packet and discard it.	virtual ts_packet_t get_ts_packet_t() = 0;};/// Interface to an object that supplies audio data to a consumer./// Audio_datasource extends the datasource protocol with methods to obtain/// information on the way the audio data is encoded and methods to support/// temporal clipping of the audio.class audio_datasource_mixin {  public:	virtual ~audio_datasource_mixin() {};	/// Returns the native format of the audio data.	virtual audio_format& get_audio_format() = 0;	/// Tells the datasource to start reading data starting from time t.	virtual void read_ahead(timestamp_t time) = 0; 	/// At what timestamp value should the audio playback stop?	virtual timestamp_t get_clip_end() = 0;	/// At what timestamp value should audio playback start?		virtual timestamp_t get_clip_begin() = 0;	/// returns m_clip_begin if the datasource took care of clip_begin otherwise it returns 0	virtual timestamp_t get_start_time() = 0;	/// Return the duration of the audio data, if known.	virtual common::duration get_dur() = 0;};class audio_datasource : public datasource, public audio_datasource_mixin {  public:	virtual ~audio_datasource() {};};class pkt_audio_datasource : public pkt_datasource, public audio_datasource_mixin {  public:	virtual ~pkt_audio_datasource() {};};/// Implementation of audio_datasource that reads raw audio data from a datasource.class raw_audio_datasource: 	virtual public audio_datasource,	virtual public lib::ref_counted_obj{  public:	raw_audio_datasource(datasource* src) :   		m_src(src),		m_fmt(audio_format(0,0,0)),		m_duration(false,0.0)  {};  	~raw_audio_datasource() {};  	    void start(lib::event_processor *evp, lib::event *callback) { m_src->start(evp,callback); };	void stop() { m_src->stop(); };  	void read_ahead(timestamp_t time){};  	void seek(timestamp_t time){};    void readdone(int len) { m_src->readdone(len); };    bool end_of_file() { return m_src->end_of_file(); };	bool buffer_full() { return false; };  	timestamp_t get_clip_end() { return -1; };	timestamp_t get_clip_begin() { return 0; };	timestamp_t get_start_time() { return 0; };	char* get_read_ptr() { return m_src->get_read_ptr(); };	int size() const { return m_src->size(); };   	audio_format& get_audio_format() { return m_fmt; };	common::duration get_dur() {	return m_duration; };    private:	datasource* m_src;  	audio_format m_fmt;  	common::duration m_duration;		};/// Interface to an object that supplies video data to a consumer.// Video_datasource is *not* a subclass of datasource: it does not deliver a stream// of bytes (like datasource and audio_datasource) but a stream of images.// It also has an ad-hoc method to determine whether audio is available too, and obtain// a datasource for that.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -