From 6e4f70a8de69884ce0caa8735d7a88915b4391d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Sun, 23 Jan 2011 01:31:41 +0200 Subject: Add a protocol handler for AES CBC decryption with PKCS7 padding MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This can later be extended to support other AES bit sizes, encryption, other crypto algorithms, reading the key from a URL, etc. In order to use it, the key and initialization vector has to be passed via AVOptions. Since such options can't be passed to protocols from the command line, the protocol is currently only for libavformat internal use. Signed-off-by: Martin Storsjö --- libavformat/Makefile | 1 + libavformat/allformats.c | 1 + libavformat/crypto.c | 170 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 172 insertions(+) create mode 100644 libavformat/crypto.c (limited to 'libavformat') diff --git a/libavformat/Makefile b/libavformat/Makefile index 5e029ed..e2e3982 100644 --- a/libavformat/Makefile +++ b/libavformat/Makefile @@ -312,6 +312,7 @@ OBJS+= avio.o aviobuf.o OBJS-$(CONFIG_APPLEHTTP_PROTOCOL) += applehttpproto.o OBJS-$(CONFIG_CONCAT_PROTOCOL) += concat.o +OBJS-$(CONFIG_CRYPTO_PROTOCOL) += crypto.o OBJS-$(CONFIG_FILE_PROTOCOL) += file.o OBJS-$(CONFIG_GOPHER_PROTOCOL) += gopher.o OBJS-$(CONFIG_HTTP_PROTOCOL) += http.o httpauth.o diff --git a/libavformat/allformats.c b/libavformat/allformats.c index 931947d..f1c3d3b 100644 --- a/libavformat/allformats.c +++ b/libavformat/allformats.c @@ -235,6 +235,7 @@ void av_register_all(void) /* protocols */ REGISTER_PROTOCOL (APPLEHTTP, applehttp); REGISTER_PROTOCOL (CONCAT, concat); + REGISTER_PROTOCOL (CRYPTO, crypto); REGISTER_PROTOCOL (FILE, file); REGISTER_PROTOCOL (GOPHER, gopher); REGISTER_PROTOCOL (HTTP, http); diff --git a/libavformat/crypto.c b/libavformat/crypto.c new file mode 100644 index 0000000..ea6012a --- /dev/null +++ b/libavformat/crypto.c @@ -0,0 +1,170 @@ +/* + * Decryption protocol handler + * Copyright (c) 2011 Martin Storsjo + * + * This file is part of Libav. + * + * Libav 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. + * + * Libav 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 Libav; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "avformat.h" +#include "libavutil/aes.h" +#include "libavutil/avstring.h" +#include "libavutil/opt.h" +#include "internal.h" +#include "url.h" + +#define MAX_BUFFER_BLOCKS 150 +#define BLOCKSIZE 16 + +typedef struct { + const AVClass *class; + URLContext *hd; + uint8_t inbuffer [BLOCKSIZE*MAX_BUFFER_BLOCKS], + outbuffer[BLOCKSIZE*MAX_BUFFER_BLOCKS]; + uint8_t *outptr; + int indata, indata_used, outdata; + int eof; + uint8_t *key; + int keylen; + uint8_t *iv; + int ivlen; + struct AVAES *aes; +} CryptoContext; + +#define OFFSET(x) offsetof(CryptoContext, x) +static const AVOption options[] = { + {"key", "AES decryption key", OFFSET(key), FF_OPT_TYPE_BINARY }, + {"iv", "AES decryption initialization vector", OFFSET(iv), FF_OPT_TYPE_BINARY }, + { NULL } +}; + +static const AVClass crypto_class = { + "crypto", av_default_item_name, options, LIBAVUTIL_VERSION_INT +}; + +static int crypto_open(URLContext *h, const char *uri, int flags) +{ + const char *nested_url; + int ret; + CryptoContext *c = h->priv_data; + + if (!av_strstart(uri, "crypto+", &nested_url) && + !av_strstart(uri, "crypto:", &nested_url)) { + av_log(h, AV_LOG_ERROR, "Unsupported url %s\n", uri); + ret = AVERROR(EINVAL); + goto err; + } + + if (c->keylen < BLOCKSIZE || c->ivlen < BLOCKSIZE) { + av_log(h, AV_LOG_ERROR, "Key or IV not set\n"); + ret = AVERROR(EINVAL); + goto err; + } + if (flags & AVIO_FLAG_WRITE) { + av_log(h, AV_LOG_ERROR, "Only decryption is supported currently\n"); + ret = AVERROR(ENOSYS); + goto err; + } + if ((ret = ffurl_open(&c->hd, nested_url, AVIO_FLAG_READ)) < 0) { + av_log(h, AV_LOG_ERROR, "Unable to open input\n"); + goto err; + } + c->aes = av_mallocz(av_aes_size); + if (!c->aes) { + ret = AVERROR(ENOMEM); + goto err; + } + + av_aes_init(c->aes, c->key, 128, 1); + + h->is_streamed = 1; + + return 0; +err: + av_free(c->key); + av_free(c->iv); + return ret; +} + +static int crypto_read(URLContext *h, uint8_t *buf, int size) +{ + CryptoContext *c = h->priv_data; + int blocks; +retry: + if (c->outdata > 0) { + size = FFMIN(size, c->outdata); + memcpy(buf, c->outptr, size); + c->outptr += size; + c->outdata -= size; + return size; + } + // We avoid using the last block until we've found EOF, + // since we'll remove PKCS7 padding at the end. So make + // sure we've got at least 2 blocks, so we can decrypt + // at least one. + while (c->indata - c->indata_used < 2*BLOCKSIZE) { + int n = ffurl_read(c->hd, c->inbuffer + c->indata, + sizeof(c->inbuffer) - c->indata); + if (n <= 0) { + c->eof = 1; + break; + } + c->indata += n; + } + blocks = (c->indata - c->indata_used) / BLOCKSIZE; + if (!blocks) + return AVERROR_EOF; + if (!c->eof) + blocks--; + av_aes_crypt(c->aes, c->outbuffer, c->inbuffer + c->indata_used, blocks, + c->iv, 1); + c->outdata = BLOCKSIZE * blocks; + c->outptr = c->outbuffer; + c->indata_used += BLOCKSIZE * blocks; + if (c->indata_used >= sizeof(c->inbuffer)/2) { + memmove(c->inbuffer, c->inbuffer + c->indata_used, + c->indata - c->indata_used); + c->indata -= c->indata_used; + c->indata_used = 0; + } + if (c->eof) { + // Remove PKCS7 padding at the end + int padding = c->outbuffer[c->outdata - 1]; + c->outdata -= padding; + } + goto retry; +} + +static int crypto_close(URLContext *h) +{ + CryptoContext *c = h->priv_data; + if (c->hd) + ffurl_close(c->hd); + av_free(c->aes); + av_free(c->key); + av_free(c->iv); + return 0; +} + +URLProtocol ff_crypto_protocol = { + .name = "crypto", + .url_open = crypto_open, + .url_read = crypto_read, + .url_close = crypto_close, + .priv_data_size = sizeof(CryptoContext), + .priv_data_class = &crypto_class, + .flags = URL_PROTOCOL_FLAG_NESTED_SCHEME, +}; -- cgit v1.1 From 84465f2180308a3e998089517e76586563fd6162 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Sun, 23 Jan 2011 23:42:18 +0200 Subject: applehttp: Handle AES-128 encrypted streams MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This should hopefully fix roundup issue 2586. This commit only implements it in the demuxer, not in the protocol handler. If desired, some of the code could be refactored to be shared by both implementations. Signed-off-by: Martin Storsjö --- libavformat/applehttp.c | 108 ++++++++++++++++++++++++++++++++++++++++++++++-- libavformat/version.h | 2 +- 2 files changed, 106 insertions(+), 4 deletions(-) (limited to 'libavformat') diff --git a/libavformat/applehttp.c b/libavformat/applehttp.c index 90b86a8..2e0e8a1 100644 --- a/libavformat/applehttp.c +++ b/libavformat/applehttp.c @@ -27,6 +27,8 @@ #define _XOPEN_SOURCE 600 #include "libavutil/avstring.h" +#include "libavutil/intreadwrite.h" +#include "libavutil/opt.h" #include "avformat.h" #include "internal.h" #include @@ -47,9 +49,17 @@ * one anonymous toplevel variant for this, to maintain the structure. */ +enum KeyType { + KEY_NONE, + KEY_AES_128, +}; + struct segment { int duration; char url[MAX_URL_SIZE]; + char key[MAX_URL_SIZE]; + enum KeyType key_type; + uint8_t iv[16]; }; /* @@ -77,6 +87,9 @@ struct variant { int needed, cur_needed; int cur_seq_no; int64_t last_load_time; + + char key_url[MAX_URL_SIZE]; + uint8_t key[16]; }; typedef struct AppleHTTPContext { @@ -160,10 +173,35 @@ static void handle_variant_args(struct variant_info *info, const char *key, } } +struct key_info { + char uri[MAX_URL_SIZE]; + char method[10]; + char iv[35]; +}; + +static void handle_key_args(struct key_info *info, const char *key, + int key_len, char **dest, int *dest_len) +{ + if (!strncmp(key, "METHOD=", key_len)) { + *dest = info->method; + *dest_len = sizeof(info->method); + } else if (!strncmp(key, "URI=", key_len)) { + *dest = info->uri; + *dest_len = sizeof(info->uri); + } else if (!strncmp(key, "IV=", key_len)) { + *dest = info->iv; + *dest_len = sizeof(info->iv); + } +} + static int parse_playlist(AppleHTTPContext *c, const char *url, struct variant *var, AVIOContext *in) { int ret = 0, duration = 0, is_segment = 0, is_variant = 0, bandwidth = 0; + enum KeyType key_type = KEY_NONE; + uint8_t iv[16] = ""; + int has_iv = 0; + char key[MAX_URL_SIZE]; char line[1024]; const char *ptr; int close_in = 0; @@ -192,6 +230,19 @@ static int parse_playlist(AppleHTTPContext *c, const char *url, ff_parse_key_value(ptr, (ff_parse_key_val_cb) handle_variant_args, &info); bandwidth = atoi(info.bandwidth); + } else if (av_strstart(line, "#EXT-X-KEY:", &ptr)) { + struct key_info info = {{0}}; + ff_parse_key_value(ptr, (ff_parse_key_val_cb) handle_key_args, + &info); + key_type = KEY_NONE; + has_iv = 0; + if (!strcmp(info.method, "AES-128")) + key_type = KEY_AES_128; + if (!strncmp(info.iv, "0x", 2) || !strncmp(info.iv, "0X", 2)) { + ff_hex_to_data(iv, info.iv + 2); + has_iv = 1; + } + av_strlcpy(key, info.uri, sizeof(key)); } else if (av_strstart(line, "#EXT-X-TARGETDURATION:", &ptr)) { if (!var) { var = new_variant(c, 0, url, NULL); @@ -242,6 +293,15 @@ static int parse_playlist(AppleHTTPContext *c, const char *url, goto fail; } seg->duration = duration; + seg->key_type = key_type; + if (has_iv) { + memcpy(seg->iv, iv, sizeof(iv)); + } else { + int seq = var->start_seq_no + var->n_segments; + memset(seg->iv, 0, sizeof(seg->iv)); + AV_WB32(seg->iv + 12, seq); + } + ff_make_absolute_url(seg->key, sizeof(seg->key), url, key); ff_make_absolute_url(seg->url, sizeof(seg->url), url, line); dynarray_add(&var->segments, &var->n_segments, seg); is_segment = 0; @@ -257,6 +317,50 @@ fail: return ret; } +static int open_input(struct variant *var) +{ + struct segment *seg = var->segments[var->cur_seq_no - var->start_seq_no]; + if (seg->key_type == KEY_NONE) { + return ffurl_open(&var->input, seg->url, AVIO_FLAG_READ); + } else if (seg->key_type == KEY_AES_128) { + char iv[33], key[33], url[MAX_URL_SIZE]; + int ret; + if (strcmp(seg->key, var->key_url)) { + URLContext *uc; + if (ffurl_open(&uc, seg->key, AVIO_FLAG_READ) == 0) { + if (ffurl_read_complete(uc, var->key, sizeof(var->key)) + != sizeof(var->key)) { + av_log(NULL, AV_LOG_ERROR, "Unable to read key file %s\n", + seg->key); + } + ffurl_close(uc); + } else { + av_log(NULL, AV_LOG_ERROR, "Unable to open key file %s\n", + seg->key); + } + av_strlcpy(var->key_url, seg->key, sizeof(var->key_url)); + } + ff_data_to_hex(iv, seg->iv, sizeof(seg->iv), 0); + ff_data_to_hex(key, var->key, sizeof(var->key), 0); + iv[32] = key[32] = '\0'; + if (strstr(seg->url, "://")) + snprintf(url, sizeof(url), "crypto+%s", seg->url); + else + snprintf(url, sizeof(url), "crypto:%s", seg->url); + if ((ret = ffurl_alloc(&var->input, url, AVIO_FLAG_READ)) < 0) + return ret; + av_set_string3(var->input->priv_data, "key", key, 0, NULL); + av_set_string3(var->input->priv_data, "iv", iv, 0, NULL); + if ((ret = ffurl_connect(var->input)) < 0) { + ffurl_close(var->input); + var->input = NULL; + return ret; + } + return 0; + } + return AVERROR(ENOSYS); +} + static int read_data(void *opaque, uint8_t *buf, int buf_size) { struct variant *v = opaque; @@ -291,9 +395,7 @@ reload: goto reload; } - ret = ffurl_open(&v->input, - v->segments[v->cur_seq_no - v->start_seq_no]->url, - AVIO_FLAG_READ); + ret = open_input(v); if (ret < 0) return ret; } diff --git a/libavformat/version.h b/libavformat/version.h index 04c5d73..9041f92 100644 --- a/libavformat/version.h +++ b/libavformat/version.h @@ -25,7 +25,7 @@ #define LIBAVFORMAT_VERSION_MAJOR 53 #define LIBAVFORMAT_VERSION_MINOR 0 -#define LIBAVFORMAT_VERSION_MICRO 1 +#define LIBAVFORMAT_VERSION_MICRO 2 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \ LIBAVFORMAT_VERSION_MINOR, \ -- cgit v1.1 From 3583d7cffe5173cc02c5476451800efdc767ce15 Mon Sep 17 00:00:00 2001 From: Alex Converse Date: Wed, 20 Apr 2011 17:25:47 +0000 Subject: Fix mov debug (u)int64_t format strings. --- libavformat/mov.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'libavformat') diff --git a/libavformat/mov.c b/libavformat/mov.c index 76dc8a1..65fcf19 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -588,7 +588,7 @@ static int mov_read_moov(MOVContext *c, AVIOContext *pb, MOVAtom atom) static int mov_read_moof(MOVContext *c, AVIOContext *pb, MOVAtom atom) { c->fragment.moof_offset = avio_tell(pb) - 8; - av_dlog(c->fc, "moof offset %llx\n", c->fragment.moof_offset); + av_dlog(c->fc, "moof offset %"PRIx64"\n", c->fragment.moof_offset); return mov_read_default(c, pb, atom); } @@ -2367,7 +2367,7 @@ static int mov_read_header(AVFormatContext *s, AVFormatParameters *ap) av_log(s, AV_LOG_ERROR, "moov atom not found\n"); return -1; } - av_dlog(mov->fc, "on_parse_exit_offset=%lld\n", avio_tell(pb)); + av_dlog(mov->fc, "on_parse_exit_offset=%"PRId64"\n", avio_tell(pb)); if (pb->seekable && mov->chapter_track > 0) mov_read_chapters(s); @@ -2416,7 +2416,7 @@ static int mov_read_packet(AVFormatContext *s, AVPacket *pkt) mov_read_default(mov, s->pb, (MOVAtom){ AV_RL32("root"), INT64_MAX }) < 0 || s->pb->eof_reached) return AVERROR_EOF; - av_dlog(s, "read fragments, offset 0x%llx\n", avio_tell(s->pb)); + av_dlog(s, "read fragments, offset 0x%"PRIx64"\n", avio_tell(s->pb)); goto retry; } sc = st->priv_data; -- cgit v1.1 From 9261e6cf3fe579fa02a96761c8e81a77bb3d8b2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Wed, 20 Apr 2011 15:36:37 +0300 Subject: rtp: Rename the open/close functions to alloc/free MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This avoids clashes if we internally want to override the global open function. Signed-off-by: Martin Storsjö --- libavformat/rdt.c | 4 ++-- libavformat/rtpdec.h | 4 ++-- libavformat/rtpdec_amr.c | 8 ++++---- libavformat/rtpdec_asf.c | 4 ++-- libavformat/rtpdec_h264.c | 4 ++-- libavformat/rtpdec_latm.c | 4 ++-- libavformat/rtpdec_mpeg4.c | 8 ++++---- libavformat/rtpdec_qcelp.c | 4 ++-- libavformat/rtpdec_qdm2.c | 4 ++-- libavformat/rtpdec_qt.c | 4 ++-- libavformat/rtpdec_svq3.c | 4 ++-- libavformat/rtpdec_vp8.c | 4 ++-- libavformat/rtpdec_xiph.c | 8 ++++---- libavformat/rtsp.c | 6 +++--- 14 files changed, 35 insertions(+), 35 deletions(-) (limited to 'libavformat') diff --git a/libavformat/rdt.c b/libavformat/rdt.c index dfb31d1..bc3c17b 100644 --- a/libavformat/rdt.c +++ b/libavformat/rdt.c @@ -551,8 +551,8 @@ static RTPDynamicProtocolHandler ff_rdt_ ## n ## _handler = { \ .codec_type = t, \ .codec_id = CODEC_ID_NONE, \ .parse_sdp_a_line = rdt_parse_sdp_line, \ - .open = rdt_new_context, \ - .close = rdt_free_context, \ + .alloc = rdt_new_context, \ + .free = rdt_free_context, \ .parse_packet = rdt_parse_packet \ } diff --git a/libavformat/rtpdec.h b/libavformat/rtpdec.h index da53efc..a4d21aa 100644 --- a/libavformat/rtpdec.h +++ b/libavformat/rtpdec.h @@ -126,8 +126,8 @@ struct RTPDynamicProtocolHandler_s { int st_index, PayloadContext *priv_data, const char *line); ///< Parse the a= line from the sdp field - PayloadContext *(*open) (void); ///< allocate any data needed by the rtp parsing for this dynamic data. - void (*close)(PayloadContext *protocol_data); ///< free any data needed by the rtp parsing for this dynamic data. + PayloadContext *(*alloc) (void); ///< allocate any data needed by the rtp parsing for this dynamic data. + void (*free)(PayloadContext *protocol_data); ///< free any data needed by the rtp parsing for this dynamic data. DynamicPayloadPacketHandlerProc parse_packet; ///< parse handler for this dynamic packet. struct RTPDynamicProtocolHandler_s *next; diff --git a/libavformat/rtpdec_amr.c b/libavformat/rtpdec_amr.c index 802e7c1..b7ff3aa 100644 --- a/libavformat/rtpdec_amr.c +++ b/libavformat/rtpdec_amr.c @@ -191,8 +191,8 @@ RTPDynamicProtocolHandler ff_amr_nb_dynamic_handler = { .codec_type = AVMEDIA_TYPE_AUDIO, .codec_id = CODEC_ID_AMR_NB, .parse_sdp_a_line = amr_parse_sdp_line, - .open = amr_new_context, - .close = amr_free_context, + .alloc = amr_new_context, + .free = amr_free_context, .parse_packet = amr_handle_packet, }; @@ -201,8 +201,8 @@ RTPDynamicProtocolHandler ff_amr_wb_dynamic_handler = { .codec_type = AVMEDIA_TYPE_AUDIO, .codec_id = CODEC_ID_AMR_WB, .parse_sdp_a_line = amr_parse_sdp_line, - .open = amr_new_context, - .close = amr_free_context, + .alloc = amr_new_context, + .free = amr_free_context, .parse_packet = amr_handle_packet, }; diff --git a/libavformat/rtpdec_asf.c b/libavformat/rtpdec_asf.c index a8326cf..ecacc0e 100644 --- a/libavformat/rtpdec_asf.c +++ b/libavformat/rtpdec_asf.c @@ -286,8 +286,8 @@ RTPDynamicProtocolHandler ff_ms_rtp_ ## n ## _handler = { \ .codec_type = t, \ .codec_id = CODEC_ID_NONE, \ .parse_sdp_a_line = asfrtp_parse_sdp_line, \ - .open = asfrtp_new_context, \ - .close = asfrtp_free_context, \ + .alloc = asfrtp_new_context, \ + .free = asfrtp_free_context, \ .parse_packet = asfrtp_parse_packet, \ } diff --git a/libavformat/rtpdec_h264.c b/libavformat/rtpdec_h264.c index 4c9b8ba..effdc1f 100644 --- a/libavformat/rtpdec_h264.c +++ b/libavformat/rtpdec_h264.c @@ -398,7 +398,7 @@ RTPDynamicProtocolHandler ff_h264_dynamic_handler = { .codec_type = AVMEDIA_TYPE_VIDEO, .codec_id = CODEC_ID_H264, .parse_sdp_a_line = parse_h264_sdp_line, - .open = h264_new_context, - .close = h264_free_context, + .alloc = h264_new_context, + .free = h264_free_context, .parse_packet = h264_handle_packet }; diff --git a/libavformat/rtpdec_latm.c b/libavformat/rtpdec_latm.c index 5bf4c19..bde34b7 100644 --- a/libavformat/rtpdec_latm.c +++ b/libavformat/rtpdec_latm.c @@ -181,7 +181,7 @@ RTPDynamicProtocolHandler ff_mp4a_latm_dynamic_handler = { .codec_type = AVMEDIA_TYPE_AUDIO, .codec_id = CODEC_ID_AAC, .parse_sdp_a_line = latm_parse_sdp_line, - .open = latm_new_context, - .close = latm_free_context, + .alloc = latm_new_context, + .free = latm_free_context, .parse_packet = latm_parse_packet }; diff --git a/libavformat/rtpdec_mpeg4.c b/libavformat/rtpdec_mpeg4.c index 9f2fcb3..7a63cc3 100644 --- a/libavformat/rtpdec_mpeg4.c +++ b/libavformat/rtpdec_mpeg4.c @@ -235,8 +235,8 @@ RTPDynamicProtocolHandler ff_mp4v_es_dynamic_handler = { .codec_type = AVMEDIA_TYPE_VIDEO, .codec_id = CODEC_ID_MPEG4, .parse_sdp_a_line = parse_sdp_line, - .open = NULL, - .close = NULL, + .alloc = NULL, + .free = NULL, .parse_packet = NULL }; @@ -245,7 +245,7 @@ RTPDynamicProtocolHandler ff_mpeg4_generic_dynamic_handler = { .codec_type = AVMEDIA_TYPE_AUDIO, .codec_id = CODEC_ID_AAC, .parse_sdp_a_line = parse_sdp_line, - .open = new_context, - .close = free_context, + .alloc = new_context, + .free = free_context, .parse_packet = aac_parse_packet }; diff --git a/libavformat/rtpdec_qcelp.c b/libavformat/rtpdec_qcelp.c index cc16ec1..325683c 100644 --- a/libavformat/rtpdec_qcelp.c +++ b/libavformat/rtpdec_qcelp.c @@ -223,7 +223,7 @@ RTPDynamicProtocolHandler ff_qcelp_dynamic_handler = { .codec_type = AVMEDIA_TYPE_AUDIO, .codec_id = CODEC_ID_QCELP, .static_payload_id = 12, - .open = qcelp_new_context, - .close = qcelp_free_context, + .alloc = qcelp_new_context, + .free = qcelp_free_context, .parse_packet = qcelp_parse_packet }; diff --git a/libavformat/rtpdec_qdm2.c b/libavformat/rtpdec_qdm2.c index 0d744be..7f5f077 100644 --- a/libavformat/rtpdec_qdm2.c +++ b/libavformat/rtpdec_qdm2.c @@ -309,7 +309,7 @@ RTPDynamicProtocolHandler ff_qdm2_dynamic_handler = { .enc_name = "X-QDM", .codec_type = AVMEDIA_TYPE_AUDIO, .codec_id = CODEC_ID_NONE, - .open = qdm2_extradata_new, - .close = qdm2_extradata_free, + .alloc = qdm2_extradata_new, + .free = qdm2_extradata_free, .parse_packet = qdm2_parse_packet, }; diff --git a/libavformat/rtpdec_qt.c b/libavformat/rtpdec_qt.c index a295ba7..8dd2968 100644 --- a/libavformat/rtpdec_qt.c +++ b/libavformat/rtpdec_qt.c @@ -244,8 +244,8 @@ RTPDynamicProtocolHandler ff_ ## m ## _rtp_ ## n ## _handler = { \ .enc_name = s, \ .codec_type = t, \ .codec_id = CODEC_ID_NONE, \ - .open = qt_rtp_new, \ - .close = qt_rtp_free, \ + .alloc = qt_rtp_new, \ + .free = qt_rtp_free, \ .parse_packet = qt_rtp_parse_packet, \ } diff --git a/libavformat/rtpdec_svq3.c b/libavformat/rtpdec_svq3.c index 8c0926212..3314342 100644 --- a/libavformat/rtpdec_svq3.c +++ b/libavformat/rtpdec_svq3.c @@ -128,7 +128,7 @@ RTPDynamicProtocolHandler ff_svq3_dynamic_handler = { .enc_name = "X-SV3V-ES", .codec_type = AVMEDIA_TYPE_VIDEO, .codec_id = CODEC_ID_NONE, // see if (config_packet) above - .open = svq3_extradata_new, - .close = svq3_extradata_free, + .alloc = svq3_extradata_new, + .free = svq3_extradata_free, .parse_packet = svq3_parse_packet, }; diff --git a/libavformat/rtpdec_vp8.c b/libavformat/rtpdec_vp8.c index 9e50cc4..026728e 100644 --- a/libavformat/rtpdec_vp8.c +++ b/libavformat/rtpdec_vp8.c @@ -148,7 +148,7 @@ RTPDynamicProtocolHandler ff_vp8_dynamic_handler = { .enc_name = "VP8", .codec_type = AVMEDIA_TYPE_VIDEO, .codec_id = CODEC_ID_VP8, - .open = vp8_new_context, - .close = vp8_free_context, + .alloc = vp8_new_context, + .free = vp8_free_context, .parse_packet = vp8_handle_packet, }; diff --git a/libavformat/rtpdec_xiph.c b/libavformat/rtpdec_xiph.c index 4d8e834..a7f36ef 100644 --- a/libavformat/rtpdec_xiph.c +++ b/libavformat/rtpdec_xiph.c @@ -389,8 +389,8 @@ RTPDynamicProtocolHandler ff_theora_dynamic_handler = { .codec_type = AVMEDIA_TYPE_VIDEO, .codec_id = CODEC_ID_THEORA, .parse_sdp_a_line = xiph_parse_sdp_line, - .open = xiph_new_context, - .close = xiph_free_context, + .alloc = xiph_new_context, + .free = xiph_free_context, .parse_packet = xiph_handle_packet }; @@ -399,7 +399,7 @@ RTPDynamicProtocolHandler ff_vorbis_dynamic_handler = { .codec_type = AVMEDIA_TYPE_AUDIO, .codec_id = CODEC_ID_VORBIS, .parse_sdp_a_line = xiph_parse_sdp_line, - .open = xiph_new_context, - .close = xiph_free_context, + .alloc = xiph_new_context, + .free = xiph_free_context, .parse_packet = xiph_handle_packet }; diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c index 58f7ddc..14111e6 100644 --- a/libavformat/rtsp.c +++ b/libavformat/rtsp.c @@ -132,8 +132,8 @@ static void init_rtp_handler(RTPDynamicProtocolHandler *handler, return; codec->codec_id = handler->codec_id; rtsp_st->dynamic_handler = handler; - if (handler->open) - rtsp_st->dynamic_protocol_context = handler->open(); + if (handler->alloc) + rtsp_st->dynamic_protocol_context = handler->alloc(); } /* parse the rtpmap description: /[/] */ @@ -526,7 +526,7 @@ void ff_rtsp_close_streams(AVFormatContext *s) rtsp_st = rt->rtsp_streams[i]; if (rtsp_st) { if (rtsp_st->dynamic_handler && rtsp_st->dynamic_protocol_context) - rtsp_st->dynamic_handler->close( + rtsp_st->dynamic_handler->free( rtsp_st->dynamic_protocol_context); av_free(rtsp_st); } -- cgit v1.1 From b1ac139d89b9fc55b70ad3411af2f75fe8b17805 Mon Sep 17 00:00:00 2001 From: Kirill Gavrilov Date: Wed, 20 Apr 2011 14:36:44 +0300 Subject: Handle unicode file names on windows MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit All file names should be in UTF-8 within libavformat. This is handled by mapping the open() function to an internal one in os_support.h for windows. fopen() could be overridden in the same way, but if that would be used from ffmpeg.c, it would add a dependency on an ff prefixed internal lavf function. Signed-off-by: Martin Storsjö --- libavformat/os_support.c | 28 ++++++++++++++++++++++++++++ libavformat/os_support.h | 5 +++++ libavformat/version.h | 2 +- 3 files changed, 34 insertions(+), 1 deletion(-) (limited to 'libavformat') diff --git a/libavformat/os_support.c b/libavformat/os_support.c index 5a3a1bb..05577b7 100644 --- a/libavformat/os_support.c +++ b/libavformat/os_support.c @@ -28,6 +28,34 @@ #include "avformat.h" #include "os_support.h" +#if defined(_WIN32) && !defined(__MINGW32CE__) +#include + +#undef open +int ff_win32_open(const char *filename_utf8, int oflag, int pmode) +{ + int fd; + int num_chars; + wchar_t *filename_w; + + /* convert UTF-8 to wide chars */ + num_chars = MultiByteToWideChar(CP_UTF8, 0, filename_utf8, -1, NULL, 0); + if (num_chars <= 0) + return -1; + filename_w = av_mallocz(sizeof(wchar_t) * num_chars); + MultiByteToWideChar(CP_UTF8, 0, filename_utf8, -1, filename_w, num_chars); + + fd = _wopen(filename_w, oflag, pmode); + av_freep(&filename_w); + + /* filename maybe be in CP_ACP */ + if (fd == -1 && !(oflag & O_CREAT)) + return open(filename_utf8, oflag, pmode); + + return fd; +} +#endif + #if CONFIG_NETWORK #include #include diff --git a/libavformat/os_support.h b/libavformat/os_support.h index dc01e64..521e997 100644 --- a/libavformat/os_support.h +++ b/libavformat/os_support.h @@ -45,6 +45,11 @@ static inline int is_dos_path(const char *path) return 0; } +#if defined(_WIN32) && !defined(__MINGW32CE__) +int ff_win32_open(const char *filename, int oflag, int pmode); +#define open ff_win32_open +#endif + #if CONFIG_NETWORK #if !HAVE_SOCKLEN_T typedef int socklen_t; diff --git a/libavformat/version.h b/libavformat/version.h index 9041f92..22b5dc9 100644 --- a/libavformat/version.h +++ b/libavformat/version.h @@ -25,7 +25,7 @@ #define LIBAVFORMAT_VERSION_MAJOR 53 #define LIBAVFORMAT_VERSION_MINOR 0 -#define LIBAVFORMAT_VERSION_MICRO 2 +#define LIBAVFORMAT_VERSION_MICRO 3 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \ LIBAVFORMAT_VERSION_MINOR, \ -- cgit v1.1