29 #include "libavutil/intreadwrite.h"
30 #include "libavutil/avstring.h"
31 #include "libavutil/opt.h"
38 #define CHUNK_HEADER_LENGTH 4 // 2bytes chunk type and 2bytes chunk length.
39 #define EXT_HEADER_LENGTH 8 // 4bytes sequence, 2bytes useless and 2bytes chunk length.
42 #define USERAGENT "User-Agent: NSPlayer/4.1.0.3856\r\n"
45 #define CLIENTGUID "Pragma: xClientGUID={c77e7400-738a-11d2-9add-0020af0a3278}\r\n"
81 int chunk_len,
res, ext_header_len;
88 chunk_type =
AV_RL16(chunk_header);
89 chunk_len =
AV_RL16(chunk_header + 2);
106 if (res != ext_header_len) {
110 *len = chunk_len - ext_header_len;
122 "Data packet length %d exceeds the in_buffer size %zu\n",
127 av_dlog(NULL,
"Data packet len = %d\n", len);
134 "Chunk length %d exceed packet length %d\n",len, mms->
asf_packet_len);
161 av_dlog(NULL,
"Header len changed from %d to %d\n",
174 "Asf header packet len = %d exceed the asf header buf size %d\n",
181 "Recv asf header data len %d != expected len %d\n", res, len);
197 "Other packet len = %d exceed the in_buffer size %zu\n",
206 av_dlog(NULL,
"Skip chunk type %d \n", chunk_type);
217 char httpname[256], path[256], host[128];
218 char *stream_selection = NULL;
228 host,
sizeof(host), &port, path,
sizeof(path), mmsh->
location);
231 ff_url_join(httpname,
sizeof(httpname),
"http", NULL, host, port,
"%s", path);
242 "Pragma: no-cache,rate=1.000000,stream-time=0,"
243 "stream-offset=0:0,request-context=%u,max-duration=0\r\n"
245 "Connection: Close\r\n",
261 memset(headers, 0,
sizeof(headers));
267 if (!stream_selection)
277 err =
snprintf(headers,
sizeof(headers),
281 "Pragma: no-cache,rate=1.000000,request-context=%u\r\n"
282 "Pragma: xPlayStrm=1\r\n"
284 "Pragma: stream-switch-count=%d\r\n"
285 "Pragma: stream-switch-entry=%s\r\n"
286 "Pragma: no-cache,rate=1.000000,stream-time=%u"
287 "Connection: Close\r\n",
294 av_dlog(NULL,
"out_buffer is %s", headers);
308 av_dlog(NULL,
"Connection successfully open\n");
313 av_dlog(NULL,
"Connection failed with error %d\n", err);
329 switch (chunk_type) {
369 int64_t timestamp,
int flags)
399 if(pos == 0 && whence == SEEK_CUR)
static int mmsh_open(URLContext *h, const char *uri, int flags)
void av_url_split(char *proto, int proto_size, char *authorization, int authorization_size, char *hostname, int hostname_size, int *port_ptr, char *path, int path_size, const char *url)
Split a URL string into components.
int request_seq
request packet sequence
URLContext * mms_hd
TCP connection handle.
#define URL_PROTOCOL_FLAG_NETWORK
URLProtocol ff_mmsh_protocol
uint8_t * read_in_ptr
Pointer for reading from incoming buffer.
static int get_http_header_data(MMSHContext *mmsh)
int is_streamed
true if streamed (no seek possible), default = false
int ffurl_connect(URLContext *uc, AVDictionary **options)
Connect an URLContext that has been allocated by ffurl_alloc.
AVIOInterruptCB interrupt_callback
static int read_data_packet(MMSHContext *mmsh, const int len)
#define EXT_HEADER_LENGTH
int ff_mms_read_header(MMSContext *mms, uint8_t *buf, const int size)
int stream_num
stream numbers.
void av_log(void *avcl, int level, const char *fmt,...) av_printf_format(3
Send the specified message to the log if the level is less than or equal to the current av_log_level...
av_dlog(ac->avr,"%d samples - audio_convert: %s to %s (%s)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt), use_generic?ac->func_descr_generic:ac->func_descr)
int header_parsed
The header has been received and parsed.
static int handle_chunk_type(MMSHContext *mmsh)
void av_freep(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
if((e=av_dict_get(options,"", NULL, AV_DICT_IGNORE_SUFFIX)))
uint8_t * asf_header
Internal handling of the ASF header.
static int64_t mmsh_seek(URLContext *h, int64_t pos, int whence)
int ff_mms_read_data(MMSContext *mms, uint8_t *buf, const int size)
#define CHUNK_HEADER_LENGTH
uint8_t in_buffer[65536]
Buffer for incoming packets.
int ffurl_alloc(URLContext **puc, const char *filename, int flags, const AVIOInterruptCB *int_cb)
Create a URLContext for accessing to the resource indicated by url, but do not initiate the connectio...
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
static ChunkType get_chunk_header(MMSHContext *mmsh, int *len)
size_t av_strlcpy(char *dst, const char *src, size_t size)
Copy the string src to dst, but no more than size - 1 bytes, and null-terminate dst.
int ffurl_closep(URLContext **hh)
Close the resource accessed by the URLContext h, and free the memory used by it.
int ff_url_join(char *str, int size, const char *proto, const char *authorization, const char *hostname, int port, const char *fmt,...)
int remaining_in_len
Reading length from incoming buffer.
static int64_t mmsh_read_seek(URLContext *h, int stream_index, int64_t timestamp, int flags)
static int mmsh_open_internal(URLContext *h, const char *uri, int flags, int timestamp, int64_t pos)
int chunk_seq
data packet sequence
size_t av_strlcat(char *dst, const char *src, size_t size)
Append the string src to the string dst, but to a total length of no more than size - 1 bytes...
int asf_header_size
Size of stored ASF header.
int ffurl_close(URLContext *h)
int ffurl_read_complete(URLContext *h, unsigned char *buf, int size)
Read as many bytes as possible (up to size), calling the read function multiple times if necessary...
static int mmsh_close(URLContext *h)
#define AVERROR_INVALIDDATA
static int mmsh_read(URLContext *h, uint8_t *buf, int size)
unbuffered private I/O API
int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
int ff_mms_asf_header_parser(MMSContext *mms)
void * av_mallocz(size_t size) av_malloc_attrib 1(1)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...