[libav-devel] [PATCH 2/2] configure: Remove the explicit disabling of ffserver

2011-03-23 Thread Martin Storsjö
It is automatically disabled on both mingw and dos due to
the lack of fork.
---
 configure |3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)

diff --git a/configure b/configure
index f7c9ff7..776eccc 100755
--- a/configure
+++ b/configure
@@ -2410,7 +2410,6 @@ case $target_os in
 LIBTARGET=arm-wince
 fi
 shlibdir_default=$bindir_default
-disable ffserver
 SLIBPREF=
 SLIBSUF=.dll
 SLIBNAME_WITH_VERSION='$(SLIBPREF)$(FULLNAME)-$(LIBVERSION)$(SLIBSUF)'
@@ -2443,7 +2442,7 @@ case $target_os in
 check_cflags -fno-common
 ;;
 *-dos|freedos|opendos)
-disable ffplay ffserver
+disable ffplay
 disable $INDEV_LIST $OUTDEV_LIST
 network_extralibs=-lsocket
 objformat=coff
-- 
1.7.3.1

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH 2/3] applehttp: Restructure the demuxer to use a custom AVIOContext

2011-03-30 Thread Martin Storsjö
This avoids issues where EOF at the end of the segment is given
the variant demuxer. Now the demuxers only see one single data
stream (as when using the applehttp protocol handler).
---
 libavformat/applehttp.c |  335 ---
 1 files changed, 169 insertions(+), 166 deletions(-)

diff --git a/libavformat/applehttp.c b/libavformat/applehttp.c
index 815013d..b9ffded 100644
--- a/libavformat/applehttp.c
+++ b/libavformat/applehttp.c
@@ -30,6 +30,9 @@
 #include avformat.h
 #include internal.h
 #include unistd.h
+#include avio_internal.h
+
+#define INITIAL_BUFFER_SIZE 32768
 
 /*
  * An apple http stream consists of a playlist with media segment files,
@@ -56,7 +59,11 @@ struct segment {
 struct variant {
 int bandwidth;
 char url[MAX_URL_SIZE];
-AVIOContext *pb;
+AVIOContext pb;
+uint8_t* read_buffer;
+URLContext *input;
+AVFormatContext *parent;
+int index;
 AVFormatContext *ctx;
 AVPacket pkt;
 int stream_offset;
@@ -66,16 +73,17 @@ struct variant {
 int start_seq_no;
 int n_segments;
 struct segment **segments;
-int needed;
+int needed, cur_needed;
+int cur_seq_no;
+int64_t last_load_time;
 };
 
 typedef struct AppleHTTPContext {
 int n_variants;
 struct variant **variants;
 int cur_seq_no;
-int64_t last_load_time;
-int64_t last_packet_dts;
-int max_start_seq, min_end_seq;
+int end_of_segment;
+int first_packet;
 } AppleHTTPContext;
 
 static int read_chomp_line(AVIOContext *s, char *buf, int maxlen)
@@ -102,8 +110,9 @@ static void free_variant_list(AppleHTTPContext *c)
 struct variant *var = c-variants[i];
 free_segment_list(var);
 av_free_packet(var-pkt);
-if (var-pb)
-avio_close(var-pb);
+av_free(var-pb.buffer);
+if (var-input)
+url_close(var-input);
 if (var-ctx) {
 var-ctx-pb = NULL;
 av_close_input_file(var-ctx);
@@ -238,7 +247,8 @@ static int parse_playlist(AppleHTTPContext *c, const char 
*url,
 }
 }
 }
-c-last_load_time = av_gettime();
+if (var)
+var-last_load_time = av_gettime();
 
 fail:
 if (close_in)
@@ -246,6 +256,74 @@ fail:
 return ret;
 }
 
+static int read_data(void* opaque, uint8_t *buf, int buf_size)
+{
+struct variant *v = opaque;
+AppleHTTPContext *c = v-parent-priv_data;
+int ret, i;
+
+restart:
+if (!v-input) {
+reload:
+if (!v-finished) {
+/* If this is a live stream and target_duration has elapsed since
+ * the last playlist reload, reload the variant playlists now. */
+int64_t now = av_gettime();
+if (now - v-last_load_time = v-target_duration*100) {
+if ((ret = parse_playlist(c, v-url, v, NULL))  0)
+return ret;
+}
+}
+if (v-cur_seq_no  v-start_seq_no) {
+av_log(NULL, AV_LOG_WARNING,
+   skipping %d segments ahead, expired from playlists\n,
+   v-start_seq_no - v-cur_seq_no);
+v-cur_seq_no = v-start_seq_no;
+}
+if (v-cur_seq_no = v-start_seq_no + v-n_segments) {
+if (v-finished)
+return AVERROR_EOF;
+while (av_gettime() - v-last_load_time 
+   v-target_duration*100) {
+if (url_interrupt_cb())
+return AVERROR_EXIT;
+usleep(100*1000);
+}
+/* Enough time has elapsed since the last reload */
+goto reload;
+}
+
+ret = url_open(v-input,
+   v-segments[v-cur_seq_no - v-start_seq_no]-url,
+   URL_RDONLY);
+if (ret  0)
+return ret;
+}
+ret = url_read(v-input, buf, buf_size);
+if (ret  0)
+return ret;
+if (ret  0  ret != AVERROR_EOF)
+return ret;
+url_close(v-input);
+v-input = NULL;
+v-cur_seq_no++;
+
+c-end_of_segment = 1;
+c-cur_seq_no = v-cur_seq_no;
+
+v-needed = 0;
+for (i = v-stream_offset; i  v-stream_offset + v-ctx-nb_streams; i++) 
{
+if (v-parent-streams[i]-discard  AVDISCARD_ALL)
+v-needed = 1;
+}
+if (!v-needed) {
+av_log(v-parent, AV_LOG_INFO, No longer receiving variant %d\n,
+   v-index);
+return AVERROR_EOF;
+}
+goto restart;
+}
+
 static int applehttp_read_header(AVFormatContext *s, AVFormatParameters *ap)
 {
 AppleHTTPContext *c = s-priv_data;
@@ -284,20 +362,35 @@ static int applehttp_read_header(AVFormatContext *s, 
AVFormatParameters *ap)
 s-duration = duration * AV_TIME_BASE;
 }
 
-c-min_end_seq = INT_MAX;
 /* Open the demuxer for each variant */
 for (i = 0; i  c-n_variants; i++) {
 struct variant *v = c-variants[i];
+AVInputFormat *in_fmt = NULL;
 if (v-n_segments == 0)

[libav-devel] [PATCH] rtsp: Use GET_PARAMETER for keep-alive for generic RTSP servers

2011-03-30 Thread Martin Storsjö
According to the RFC, GET_PARAMETER should be used for
this, and according to a report from Tim Ouellette,
OPTIONS doesn't work for keeping the connection alive for some
servers. Also, live555 uses GET_PARAMETER for this purpose.
---
 libavformat/rtspdec.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/libavformat/rtspdec.c b/libavformat/rtspdec.c
index 571e76d..e2ba76e 100644
--- a/libavformat/rtspdec.c
+++ b/libavformat/rtspdec.c
@@ -340,7 +340,7 @@ retry:
 
 /* send dummy request to keep TCP connection alive */
 if ((av_gettime() - rt-last_cmd_time) / 100 = rt-timeout / 2) {
-if (rt-server_type == RTSP_SERVER_WMS) {
+if (rt-server_type != RTSP_SERVER_REAL) {
 ff_rtsp_send_cmd_async(s, GET_PARAMETER, rt-control_uri, NULL);
 } else {
 ff_rtsp_send_cmd_async(s, OPTIONS, *, NULL);
-- 
1.7.3.1

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH] configure: Initial support for --target-os=symbian

2011-03-30 Thread Martin Storsjö
On Wed, 30 Mar 2011, Måns Rullgård wrote:

 Martin Storsjö mar...@martin.st writes:
 
  On Wed, 23 Mar 2011, Måns Rullgård wrote:
 
  Martin Storsjö mar...@martin.st writes:
  
   On Wed, 23 Mar 2011, Måns Rullgård wrote:
  
   Martin Storsjö mar...@martin.st writes:
   
+enable dos_paths
+ASFLAGS=$(echo $(filter_out --include* $ASFLAGS))
   
   filter_asflags=filter_out --include*
  
   Ah yes - I tried that initially, but this is past the section where 
   cflags 
   are added to ASFLAGS (add_asflags $extra_cflags, quite soon after the 
   compiler detection section) - setting filter_asflags here doesn't have 
   any 
   effect.
  
   Do you prefer moving part this up a bit, as a separate block, next to 
   the 
   compiler section? Something like this:
  
   if [ $target_os = symbian ]; then
   filter_asflags=filter_out --include*
   endif
  
  No, that's worse.  Bother me about it later today, I'll try to think of
  a nice solution.
 
  Ping - any better suggestion?
 
 What does the --include do, and can we add it ourselves somehow?  That
 would solve the problem and make life easier for the user.

The --include is for including a toolchain (gcc or rvct) specific header 
that all the platform headers require to be present before they are 
included.

If we'd add it ourselves, it would be something like this for the gcce 
case:

add_cflags --include=$EPOCROOT/epoc32/include/gcce/gcce.h

It's kinda ugly to have to rely on an external env variable for the SDK 
root, although $EPOCROOT is the standard env var name for this in symbian 
stuff.

// Martin___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH] configure: Initial support for --target-os=symbian

2011-03-30 Thread Martin Storsjö
On Wed, 30 Mar 2011, Måns Rullgård wrote:

 Martin Storsjö mar...@martin.st writes:
 
  On Wed, 30 Mar 2011, Måns Rullgård wrote:
 
  Martin Storsjö mar...@martin.st writes:
  
   On Wed, 23 Mar 2011, Måns Rullgård wrote:
  
   Martin Storsjö mar...@martin.st writes:
   
On Wed, 23 Mar 2011, Måns Rullgård wrote:
   
Martin Storsjö mar...@martin.st writes:

 +enable dos_paths
 +ASFLAGS=$(echo $(filter_out --include* $ASFLAGS))

filter_asflags=filter_out --include*
   
Ah yes - I tried that initially, but this is past the section where 
cflags 
are added to ASFLAGS (add_asflags $extra_cflags, quite soon after 
the 
compiler detection section) - setting filter_asflags here doesn't 
have any 
effect.
   
Do you prefer moving part this up a bit, as a separate block, next to 
the 
compiler section? Something like this:
   
if [ $target_os = symbian ]; then
filter_asflags=filter_out --include*
endif
   
   No, that's worse.  Bother me about it later today, I'll try to think of
   a nice solution.
  
   Ping - any better suggestion?
  
  What does the --include do, and can we add it ourselves somehow?  That
  would solve the problem and make life easier for the user.
 
  The --include is for including a toolchain (gcc or rvct) specific header 
  that all the platform headers require to be present before they are 
  included.
 
  If we'd add it ourselves, it would be something like this for the gcce 
  case:
 
  add_cflags --include=$EPOCROOT/epoc32/include/gcce/gcce.h
 
  It's kinda ugly to have to rely on an external env variable for the SDK 
  root, although $EPOCROOT is the standard env var name for this in symbian 
  stuff.
 
 Can we use the existing --sysinclude flag for this?

Yes, that seems to work.

Tests like _FILE_OFFSET_BITS=64 that are done before the target-os switch 
(where the include flag is added to cflags) do fail even though they would 
have succeeded otherwise, but that's not really an issue, I'm not sure the 
os itself supports such files anyway.

// Martin___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH] configure: Initial support for --target-os=symbian

2011-03-30 Thread Martin Storsjö
---
 configure |9 -
 1 files changed, 8 insertions(+), 1 deletions(-)

diff --git a/configure b/configure
index fab4f2b..5e76a28 100755
--- a/configure
+++ b/configure
@@ -1822,7 +1822,7 @@ set_default host_cc
 
 exesuf() {
 case $1 in
-mingw32*|cygwin*|*-dos|freedos|opendos|os/2*) echo .exe ;;
+mingw32*|cygwin*|*-dos|freedos|opendos|os/2*|symbian) echo .exe ;;
 esac
 }
 
@@ -2480,6 +2480,13 @@ case $target_os in
 add_cppflags -D_QNX_SOURCE
 network_extralibs=-lsocket
 ;;
+symbian)
+SLIBSUF=.dll
+enable dos_paths
+# This include flag is added here instead of in extra_cflags,
+# since it mustn't end up in asflags
+add_cflags --include=$sysinclude/gcce/gcce.h
+;;
 none)
 ;;
 *)
-- 
1.7.3.1

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH 1/3] applehttp: Move finished and target_duration to the variant struct

2011-03-31 Thread Martin Storsjö
This is a preparation for a restructuring of the demuxer, to
minimize the later diff.
---
 libavformat/applehttp.c |   40 +---
 1 files changed, 25 insertions(+), 15 deletions(-)

diff --git a/libavformat/applehttp.c b/libavformat/applehttp.c
index 56fb795..815013d 100644
--- a/libavformat/applehttp.c
+++ b/libavformat/applehttp.c
@@ -61,6 +61,8 @@ struct variant {
 AVPacket pkt;
 int stream_offset;
 
+int finished;
+int target_duration;
 int start_seq_no;
 int n_segments;
 struct segment **segments;
@@ -68,8 +70,6 @@ struct variant {
 };
 
 typedef struct AppleHTTPContext {
-int target_duration;
-int finished;
 int n_variants;
 struct variant **variants;
 int cur_seq_no;
@@ -170,9 +170,10 @@ static int parse_playlist(AppleHTTPContext *c, const char 
*url,
 goto fail;
 }
 
-if (var)
+if (var) {
 free_segment_list(var);
-c-finished = 0;
+var-finished = 0;
+}
 while (!in-eof_reached) {
 read_chomp_line(in, line, sizeof(line));
 if (av_strstart(line, #EXT-X-STREAM-INF:, ptr)) {
@@ -182,7 +183,14 @@ static int parse_playlist(AppleHTTPContext *c, const char 
*url,
info);
 bandwidth = atoi(info.bandwidth);
 } else if (av_strstart(line, #EXT-X-TARGETDURATION:, ptr)) {
-c-target_duration = atoi(ptr);
+if (!var) {
+var = new_variant(c, 0, url, NULL);
+if (!var) {
+ret = AVERROR(ENOMEM);
+goto fail;
+}
+}
+var-target_duration = atoi(ptr);
 } else if (av_strstart(line, #EXT-X-MEDIA-SEQUENCE:, ptr)) {
 if (!var) {
 var = new_variant(c, 0, url, NULL);
@@ -193,7 +201,8 @@ static int parse_playlist(AppleHTTPContext *c, const char 
*url,
 }
 var-start_seq_no = atoi(ptr);
 } else if (av_strstart(line, #EXT-X-ENDLIST, ptr)) {
-c-finished = 1;
+if (var)
+var-finished = 1;
 } else if (av_strstart(line, #EXTINF:, ptr)) {
 is_segment = 1;
 duration   = atoi(ptr);
@@ -268,7 +277,7 @@ static int applehttp_read_header(AVFormatContext *s, 
AVFormatParameters *ap)
 
 /* If this isn't a live stream, calculate the total duration of the
  * stream. */
-if (c-finished) {
+if (c-variants[0]-finished) {
 int64_t duration = 0;
 for (i = 0; i  c-variants[0]-n_segments; i++)
 duration += c-variants[0]-segments[i]-duration;
@@ -306,7 +315,7 @@ static int applehttp_read_header(AVFormatContext *s, 
AVFormatParameters *ap)
 c-cur_seq_no = c-max_start_seq;
 /* If this is a live stream with more than 3 segments, start at the
  * third last segment. */
-if (!c-finished  c-min_end_seq - c-max_start_seq  3)
+if (!c-variants[0]-finished  c-min_end_seq - c-max_start_seq  3)
 c-cur_seq_no = c-min_end_seq - 2;
 
 return 0;
@@ -326,7 +335,7 @@ static int open_variant(AppleHTTPContext *c, struct variant 
*var, int skip)
 return 0;
 }
 if (c-cur_seq_no - var-start_seq_no = var-n_segments)
-return c-finished ? AVERROR_EOF : 0;
+return c-variants[0]-finished ? AVERROR_EOF : 0;
 ret = avio_open(var-pb,
 var-segments[c-cur_seq_no - var-start_seq_no]-url,
 URL_RDONLY);
@@ -390,7 +399,7 @@ start:
 } else if (!var-pb  var-needed) {
 if (first)
 av_log(s, AV_LOG_DEBUG, Opening variant stream %d\n, i);
-if (first  !c-finished)
+if (first  !var-finished)
 if ((ret = parse_playlist(c, var-url, var, NULL))  0)
 return ret;
 ret = open_variant(c, var, first);
@@ -442,11 +451,11 @@ start:
 first = 0;
 c-cur_seq_no++;
 reload:
-if (!c-finished) {
+if (!c-variants[0]-finished) {
 /* If this is a live stream and target_duration has elapsed since
  * the last playlist reload, reload the variant playlists now. */
 int64_t now = av_gettime();
-if (now - c-last_load_time = c-target_duration*100) {
+if (now - c-last_load_time = 
c-variants[0]-target_duration*100) {
 c-max_start_seq = 0;
 c-min_end_seq   = INT_MAX;
 for (i = 0; i  c-n_variants; i++) {
@@ -473,9 +482,10 @@ reload:
 goto start;
 /* We've reached the end of the playlists - return eof if this is a
  * non-live stream, wait until the next playlist reload if it is live. */
-if (c-finished)
+if (c-variants[0]-finished)
 return AVERROR_EOF;
-while (av_gettime() - c-last_load_time  c-target_duration*100) {
+while (av_gettime() - c-last_load_time 
+   c-variants[0]-target_duration*100) {
 if (url_interrupt_cb())
 return 

[libav-devel] [PATCH 2/3] applehttp: Restructure the demuxer to use a custom AVIOContext

2011-03-31 Thread Martin Storsjö
This avoids issues where EOF at the end of the segment is given
the variant demuxer. Now the demuxers only see one single data
stream (as when using the applehttp protocol handler).
---
 libavformat/applehttp.c |  335 ---
 1 files changed, 169 insertions(+), 166 deletions(-)

diff --git a/libavformat/applehttp.c b/libavformat/applehttp.c
index 815013d..db1dc61 100644
--- a/libavformat/applehttp.c
+++ b/libavformat/applehttp.c
@@ -30,6 +30,9 @@
 #include avformat.h
 #include internal.h
 #include unistd.h
+#include avio_internal.h
+
+#define INITIAL_BUFFER_SIZE 32768
 
 /*
  * An apple http stream consists of a playlist with media segment files,
@@ -56,7 +59,11 @@ struct segment {
 struct variant {
 int bandwidth;
 char url[MAX_URL_SIZE];
-AVIOContext *pb;
+AVIOContext pb;
+uint8_t* read_buffer;
+URLContext *input;
+AVFormatContext *parent;
+int index;
 AVFormatContext *ctx;
 AVPacket pkt;
 int stream_offset;
@@ -66,16 +73,17 @@ struct variant {
 int start_seq_no;
 int n_segments;
 struct segment **segments;
-int needed;
+int needed, cur_needed;
+int cur_seq_no;
+int64_t last_load_time;
 };
 
 typedef struct AppleHTTPContext {
 int n_variants;
 struct variant **variants;
 int cur_seq_no;
-int64_t last_load_time;
-int64_t last_packet_dts;
-int max_start_seq, min_end_seq;
+int end_of_segment;
+int first_packet;
 } AppleHTTPContext;
 
 static int read_chomp_line(AVIOContext *s, char *buf, int maxlen)
@@ -102,8 +110,9 @@ static void free_variant_list(AppleHTTPContext *c)
 struct variant *var = c-variants[i];
 free_segment_list(var);
 av_free_packet(var-pkt);
-if (var-pb)
-avio_close(var-pb);
+av_free(var-pb.buffer);
+if (var-input)
+url_close(var-input);
 if (var-ctx) {
 var-ctx-pb = NULL;
 av_close_input_file(var-ctx);
@@ -238,7 +247,8 @@ static int parse_playlist(AppleHTTPContext *c, const char 
*url,
 }
 }
 }
-c-last_load_time = av_gettime();
+if (var)
+var-last_load_time = av_gettime();
 
 fail:
 if (close_in)
@@ -246,6 +256,74 @@ fail:
 return ret;
 }
 
+static int read_data(void* opaque, uint8_t *buf, int buf_size)
+{
+struct variant *v = opaque;
+AppleHTTPContext *c = v-parent-priv_data;
+int ret, i;
+
+restart:
+if (!v-input) {
+reload:
+if (!v-finished) {
+/* If this is a live stream and target_duration has elapsed since
+ * the last playlist reload, reload the variant playlists now. */
+int64_t now = av_gettime();
+if (now - v-last_load_time = v-target_duration*100) {
+if ((ret = parse_playlist(c, v-url, v, NULL))  0)
+return ret;
+}
+}
+if (v-cur_seq_no  v-start_seq_no) {
+av_log(NULL, AV_LOG_WARNING,
+   skipping %d segments ahead, expired from playlists\n,
+   v-start_seq_no - v-cur_seq_no);
+v-cur_seq_no = v-start_seq_no;
+}
+if (v-cur_seq_no = v-start_seq_no + v-n_segments) {
+if (v-finished)
+return AVERROR_EOF;
+while (av_gettime() - v-last_load_time 
+   v-target_duration*100) {
+if (url_interrupt_cb())
+return AVERROR_EXIT;
+usleep(100*1000);
+}
+/* Enough time has elapsed since the last reload */
+goto reload;
+}
+
+ret = url_open(v-input,
+   v-segments[v-cur_seq_no - v-start_seq_no]-url,
+   URL_RDONLY);
+if (ret  0)
+return ret;
+}
+ret = url_read(v-input, buf, buf_size);
+if (ret  0)
+return ret;
+if (ret  0  ret != AVERROR_EOF)
+return ret;
+url_close(v-input);
+v-input = NULL;
+v-cur_seq_no++;
+
+c-end_of_segment = 1;
+c-cur_seq_no = v-cur_seq_no;
+
+v-needed = 0;
+for (i = v-stream_offset; i  v-stream_offset + v-ctx-nb_streams; i++) 
{
+if (v-parent-streams[i]-discard  AVDISCARD_ALL)
+v-needed = 1;
+}
+if (!v-needed) {
+av_log(v-parent, AV_LOG_INFO, No longer receiving variant %d\n,
+   v-index);
+return AVERROR_EOF;
+}
+goto restart;
+}
+
 static int applehttp_read_header(AVFormatContext *s, AVFormatParameters *ap)
 {
 AppleHTTPContext *c = s-priv_data;
@@ -284,20 +362,35 @@ static int applehttp_read_header(AVFormatContext *s, 
AVFormatParameters *ap)
 s-duration = duration * AV_TIME_BASE;
 }
 
-c-min_end_seq = INT_MAX;
 /* Open the demuxer for each variant */
 for (i = 0; i  c-n_variants; i++) {
 struct variant *v = c-variants[i];
+AVInputFormat *in_fmt = NULL;
 if (v-n_segments == 0)

[libav-devel] [PATCH 3/3] applehttp: Merge two for loops

2011-03-31 Thread Martin Storsjö
The previous diff didn't do this straight away, to keep the
diff slightly simpler.
---
 libavformat/applehttp.c |   17 +++--
 1 files changed, 7 insertions(+), 10 deletions(-)

diff --git a/libavformat/applehttp.c b/libavformat/applehttp.c
index db1dc61..fab7a26 100644
--- a/libavformat/applehttp.c
+++ b/libavformat/applehttp.c
@@ -509,9 +509,15 @@ static int applehttp_read_seek(AVFormatContext *s, int 
stream_index,
 if ((flags  AVSEEK_FLAG_BYTE) || !c-variants[0]-finished)
 return AVERROR(ENOSYS);
 
-/* Reset the variants */
+timestamp = av_rescale_rnd(timestamp, 1, stream_index = 0 ?
+   s-streams[stream_index]-time_base.den :
+   AV_TIME_BASE, flags  AVSEEK_FLAG_BACKWARD ?
+   AV_ROUND_DOWN : AV_ROUND_UP);
+ret = AVERROR(EIO);
 for (i = 0; i  c-n_variants; i++) {
+/* Reset reading */
 struct variant *var = c-variants[i];
+int64_t pos = 0;
 if (var-input) {
 url_close(var-input);
 var-input = NULL;
@@ -519,16 +525,7 @@ static int applehttp_read_seek(AVFormatContext *s, int 
stream_index,
 av_free_packet(var-pkt);
 reset_packet(var-pkt);
 var-pb.eof_reached = 0;
-}
 
-timestamp = av_rescale_rnd(timestamp, 1, stream_index = 0 ?
-   s-streams[stream_index]-time_base.den :
-   AV_TIME_BASE, flags  AVSEEK_FLAG_BACKWARD ?
-   AV_ROUND_DOWN : AV_ROUND_UP);
-ret = AVERROR(EIO);
-for (i = 0; i  c-n_variants; i++) {
-struct variant *var = c-variants[i];
-int64_t pos = 0;
 /* Locate the segment that contains the target timestamp */
 for (j = 0; j  var-n_segments; j++) {
 if (timestamp = pos 
-- 
1.7.3.1

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH 2/3] applehttp: Restructure the demuxer to use a custom AVIOContext

2011-04-04 Thread Martin Storsjö
On Fri, 1 Apr 2011, Diego Biurrun wrote:

 On Thu, Mar 31, 2011 at 11:19:35PM +0300, Martin Storsjö wrote:
  This avoids issues where EOF at the end of the segment is given
  the variant demuxer. Now the demuxers only see one single data
  stream (as when using the applehttp protocol handler).
 
 .. some nits ..
 
  --- a/libavformat/applehttp.c
  +++ b/libavformat/applehttp.c
  @@ -246,6 +256,74 @@ fail:
   
  +static int read_data(void* opaque, uint8_t *buf, int buf_size)
 
 *opaque
 
  +if (!v-finished) {
  +/* If this is a live stream and target_duration has elapsed 
  since
  + * the last playlist reload, reload the variant playlists now. 
  */
  +int64_t now = av_gettime();
  +if (now - v-last_load_time = v-target_duration*100) {
  +if ((ret = parse_playlist(c, v-url, v, NULL))  0)
  +return ret;
  +}
  +}
 
 I'd merge all of this into one if-statement and drop the variable, i.e.
 
if (!v-finished 
/* If this is a live stream and target_duration has elapsed since
 * the last playlist reload, reload the variant playlists now. */
av_gettime() - v-last_load_time = v-target_duration * 100 
(ret = parse_playlist(c, v-url, v, NULL))  0)
return ret;

Both fixed locally, thanks!

// Martin___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH 0/3] applehttp demuxer rewrite

2011-04-04 Thread Martin Storsjö
On Thu, 31 Mar 2011, Luca Barbato wrote:

 All in all, patch ok, we need to keep the protocol since it still fixes
 some issues though.

Pushed with the changes Diego suggested.

// Martin
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH 03/15] avio: make url_alloc internal.

2011-04-04 Thread Martin Storsjö
On Sun, 3 Apr 2011, Ronald S. Bultje wrote:

 On Thu, Mar 31, 2011 at 9:14 AM, Anton Khirnov an...@khirnov.net wrote:
  ---
   libavformat/avio.c |    9 +++--
   libavformat/avio.h |   14 +-
   libavformat/mmsh.c |    5 +++--
   libavformat/rtsp.c |    5 +++--
   libavformat/url.h  |   43 +++
   5 files changed, 57 insertions(+), 19 deletions(-)
   create mode 100644 libavformat/url.h
 [..]
  -        if (url_alloc(rt-rtsp_hd, httpname, URL_RDONLY)  0) {
  +        if (ffurl_alloc(rt-rtsp_hd, httpname, URL_RDONLY)  0) {
 
 So I see this function doing a lot of stuff, alloc, init, etc.
 
 - now that URLProtocol/URLContext will be internal, do people want to
 get rid of the superfluous allocations?

I don't see a huge reason to redesign it, just to avoid one malloc. I'd 
rather keep the function doing the alloc - that simplifies making this API 
public at a later point, if that ever is desired.

 - can anyone remind me what is url_alloc_for_protocol() vs. url_alloc()?

url_alloc_for_protocol initializes the URLContext once the URLProtocol to 
use is known, while url_alloc chooses which URLProtocol to use to handle 
the url.

Earlier, we had only url_open() and url_open_protocol(). IIRC, 
url_open_protocol() isn't used anywhere, and thus deprecated now. When we 
split open into alloc + connect (in order to be able to set private 
options inbetween), this became:

- url_open, calling url_alloc + url_connect
- url_open_protocol, calling url_alloc_for_protocol + url_connect
- url_alloc, iterating over protocols, choosing the one to use, then
  calling url_alloc_for_protocol on it
- url_alloc_for_protocol, initializing the urlcontext for the chosen 
  protocol
- url_connect, calling the actual open/init function on the urlprotocol 
  (once the caller has set the private options)

Of these, url_open is the only one used normally, while 
url_alloc+url_connect are called explicitly when setting private options. 
url_open_protocol is deprecated now, and I don't see too much a need to 
keep a public symbol for url_alloc_for_protocol either. It can just as 
well be a static function in avio.c, if we want to keep the number of 
visible symbols down. Then we'd have ffurl_open, ffurl_alloc, 
ffurl_connect.

// Martin___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH] Factor ff_network_wait_fd and use it on udp proto

2011-04-05 Thread Martin Storsjö
On Mon, 4 Apr 2011, Luca Barbato wrote:

 diff --git a/libavformat/udp.c b/libavformat/udp.c
 index 8d50218..4e32a1e 100644
 --- a/libavformat/udp.c
 +++ b/libavformat/udp.c
 @@ -444,57 +444,41 @@ static int udp_open(URLContext *h, const char *uri, int 
 flags)
  return AVERROR(EIO);
  }
  
 +
  static int udp_read(URLContext *h, uint8_t *buf, int size)

Stray whitespace change


  
 +
  static int udp_write(URLContext *h, const uint8_t *buf, int size)

Same here


Except for that, looks good to me, and worked ok in a quick test.

// Martin
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [ANNOUNCEMENT] vo-aacenc 0.1.0 and vo-amrwbenc 0.1.0

2011-04-07 Thread Martin Storsjö
Hi,

When Google released the code for Android Gingerbread in December, they 
released source code for two new Apache 2.0 licensed audio encoders 
provided by VisualOn, for AAC and AMR-WB.

These encoders are now wrapped up in standalone encoder libraries, 
vo-aacenc and vo-amrwbenc, just as for opencore-amr (which included an 
AMR-NB encoder and decoder, and an AMR-WB decoder) before.

These projects, while not sharing any code with opencore-amr, are quite 
similar in their heritage and style (being a standalone wrapping of codecs 
from another framework), and are hosted under the opencore-amr sourceforge 
project for now. The release files are available at 
https://sourceforge.net/projects/opencore-amr/files/, and the code is 
available in git at 
git://opencore-amr.git.sourceforge.net/gitroot/opencore-amr/vo-aacenc
and 
git://opencore-amr.git.sourceforge.net/gitroot/opencore-amr/vo-amrwbenc 
respectively.

The same code is also available on github, at 
https://github.com/mstorsjo/vo-aacenc and 
https://github.com/mstorsjo/vo-amrwbenc for easier collaboration.

The vo-amrwbenc library provides a very minimal interface similar to what 
the old, unredistributable libamrwb used, so any code that used that 
library can easily be adapted to use vo-amrwbenc instead. The vo-aacenc 
library, on the other hand, directly exposes the VisualOn audio codec 
interface. Both libraries come with an optional example program showing 
how to use their interfaces.

The code in these libraries are (just as for opencore-amr) relicensed 
versions of 3GPP reference code, but all of it has, to the best of my 
knowledge, been checked for legal correctness by Google.

In addition to the original reference code, they also contain some 
optimizations for ARM, initially done by VisualOn, and further improved by 
Mans Rullgard.

Regards,
// Martin Storsjo
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH 1/2] Add an AAC encoder by using the libvo-aacenc library

2011-04-07 Thread Martin Storsjö
---
 Changelog |1 +
 configure |6 ++
 libavcodec/Makefile   |1 +
 libavcodec/allcodecs.c|1 +
 libavcodec/libvo-aacenc.c |  132 +
 5 files changed, 141 insertions(+), 0 deletions(-)
 create mode 100644 libavcodec/libvo-aacenc.c

diff --git a/Changelog b/Changelog
index ec09c28..6a255d4 100644
--- a/Changelog
+++ b/Changelog
@@ -83,6 +83,7 @@ version next:
 - Linux framebuffer input device added
 - Chronomaster DFA decoder
 - Mobotix MxPEG decoder
+- AAC encoding via libvo-aacenc
 
 
 version 0.6:
diff --git a/configure b/configure
index 92a809f..8880fba 100755
--- a/configure
+++ b/configure
@@ -178,6 +178,7 @@ External library support:
   --enable-libschroedinger enable Dirac support via libschroedinger [no]
   --enable-libspeexenable Speex decoding via libspeex [no]
   --enable-libtheora   enable Theora encoding via libtheora [no]
+  --enable-libvo-aacencenable AAC encoding via libvo-aacenc [no]
   --enable-libvorbis   enable Vorbis encoding via libvorbis,
native implementation exists [no]
   --enable-libvpx  enable VP8 support via libvpx [no]
@@ -937,6 +938,7 @@ CONFIG_LIST=
 libschroedinger
 libspeex
 libtheora
+libvo_aacenc
 libvorbis
 libvpx
 libx264
@@ -1384,6 +1386,7 @@ libschroedinger_decoder_deps=libschroedinger
 libschroedinger_encoder_deps=libschroedinger
 libspeex_decoder_deps=libspeex
 libtheora_encoder_deps=libtheora
+libvo_aacenc_encoder_deps=libvo_aacenc
 libvorbis_encoder_deps=libvorbis
 libvpx_decoder_deps=libvpx
 libvpx_encoder_deps=libvpx
@@ -2525,6 +2528,7 @@ die_license_disabled nonfree libfaac
 
 die_license_disabled version3 libopencore_amrnb
 die_license_disabled version3 libopencore_amrwb
+die_license_disabled version3 libvo_aacenc
 
 enabled version3  { enabled gpl  enable gplv3 || enable lgplv3; }
 
@@ -2864,6 +2868,7 @@ enabled librtmp require_pkg_config librtmp 
librtmp/rtmp.h RTMP_Socket
 enabled libschroedinger  require_pkg_config schroedinger-1.0 
schroedinger/schro.h schro_init
 enabled libspeexrequire  libspeex speex/speex.h speex_decoder_init 
-lspeex
 enabled libtheora   require  libtheora theora/theoraenc.h th_info_init 
-ltheoraenc -ltheoradec -logg
+enabled libvo_aacenc  require libvo_aacenc vo-aacenc/voAAC.h voGetAACEncAPI 
-lvo-aacenc
 enabled libvorbis   require  libvorbis vorbis/vorbisenc.h vorbis_info_init 
-lvorbisenc -lvorbis -logg
 enabled libvpx  {
 enabled libvpx_decoder  { check_lib2 vpx/vpx_decoder.h vpx/vp8dx.h 
vpx_codec_dec_init_ver -lvpx ||
@@ -3132,6 +3137,7 @@ echo libschroedinger enabled   ${libschroedinger-no}
 echo libspeex enabled  ${libspeex-no}
 echo libtheora enabled ${libtheora-no}
 echo libva enabled ${vaapi-no}
+echo libvo-aacenc support  ${libvo_aacenc-no}
 echo libvorbis enabled ${libvorbis-no}
 echo libvpx enabled${libvpx-no}
 echo libx264 enabled   ${libx264-no}
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 837f7e2..e9c40e4 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -568,6 +568,7 @@ OBJS-$(CONFIG_LIBSCHROEDINGER_ENCODER)+= 
libschroedingerenc.o \
  libdirac_libschro.o
 OBJS-$(CONFIG_LIBSPEEX_DECODER)   += libspeexdec.o
 OBJS-$(CONFIG_LIBTHEORA_ENCODER)  += libtheoraenc.o
+OBJS-$(CONFIG_LIBVO_AACENC_ENCODER)   += libvo-aacenc.o mpeg4audio.o
 OBJS-$(CONFIG_LIBVORBIS_ENCODER)  += libvorbis.o vorbis_data.o
 OBJS-$(CONFIG_LIBVPX_DECODER) += libvpxdec.o
 OBJS-$(CONFIG_LIBVPX_ENCODER) += libvpxenc.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index 7636392..e0323ac 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -366,6 +366,7 @@ void avcodec_register_all(void)
 REGISTER_ENCDEC  (LIBSCHROEDINGER, libschroedinger);
 REGISTER_DECODER (LIBSPEEX, libspeex);
 REGISTER_ENCODER (LIBTHEORA, libtheora);
+REGISTER_ENCODER (LIBVO_AACENC, libvo_aacenc);
 REGISTER_ENCODER (LIBVORBIS, libvorbis);
 REGISTER_ENCDEC  (LIBVPX, libvpx);
 REGISTER_ENCODER (LIBX264, libx264);
diff --git a/libavcodec/libvo-aacenc.c b/libavcodec/libvo-aacenc.c
new file mode 100644
index 000..34389f1
--- /dev/null
+++ b/libavcodec/libvo-aacenc.c
@@ -0,0 +1,132 @@
+/*
+ * AAC encoder wrapper
+ * Copyright (c) 2010 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 

[libav-devel] [PATCH 2/2] Add support for AMR-WB encoding via libvo-amrwbenc

2011-04-07 Thread Martin Storsjö
The wrapper code is based on the libamr wrapper removed in SVN rev 19365.
---
 Changelog   |1 +
 configure   |6 ++
 doc/general.texi|3 +-
 libavcodec/Makefile |1 +
 libavcodec/allcodecs.c  |1 +
 libavcodec/libvo-amrwbenc.c |  128 +++
 6 files changed, 139 insertions(+), 1 deletions(-)
 create mode 100644 libavcodec/libvo-amrwbenc.c

diff --git a/Changelog b/Changelog
index 6a255d4..87ec036 100644
--- a/Changelog
+++ b/Changelog
@@ -84,6 +84,7 @@ version next:
 - Chronomaster DFA decoder
 - Mobotix MxPEG decoder
 - AAC encoding via libvo-aacenc
+- AMR-WB encoding via libvo-amrwbenc
 
 
 version 0.6:
diff --git a/configure b/configure
index 8880fba..c632ce5 100755
--- a/configure
+++ b/configure
@@ -179,6 +179,7 @@ External library support:
   --enable-libspeexenable Speex decoding via libspeex [no]
   --enable-libtheora   enable Theora encoding via libtheora [no]
   --enable-libvo-aacencenable AAC encoding via libvo-aacenc [no]
+  --enable-libvo-amrwbenc  enable AMR-WB encoding via libvo-amrwbenc [no]
   --enable-libvorbis   enable Vorbis encoding via libvorbis,
native implementation exists [no]
   --enable-libvpx  enable VP8 support via libvpx [no]
@@ -939,6 +940,7 @@ CONFIG_LIST=
 libspeex
 libtheora
 libvo_aacenc
+libvo_amrwbenc
 libvorbis
 libvpx
 libx264
@@ -1387,6 +1389,7 @@ libschroedinger_encoder_deps=libschroedinger
 libspeex_decoder_deps=libspeex
 libtheora_encoder_deps=libtheora
 libvo_aacenc_encoder_deps=libvo_aacenc
+libvo_amrwbenc_encoder_deps=libvo_amrwbenc
 libvorbis_encoder_deps=libvorbis
 libvpx_decoder_deps=libvpx
 libvpx_encoder_deps=libvpx
@@ -2529,6 +2532,7 @@ die_license_disabled nonfree libfaac
 die_license_disabled version3 libopencore_amrnb
 die_license_disabled version3 libopencore_amrwb
 die_license_disabled version3 libvo_aacenc
+die_license_disabled version3 libvo_amrwbenc
 
 enabled version3  { enabled gpl  enable gplv3 || enable lgplv3; }
 
@@ -2869,6 +2873,7 @@ enabled libschroedinger  require_pkg_config 
schroedinger-1.0 schroedinger/schr
 enabled libspeexrequire  libspeex speex/speex.h speex_decoder_init 
-lspeex
 enabled libtheora   require  libtheora theora/theoraenc.h th_info_init 
-ltheoraenc -ltheoradec -logg
 enabled libvo_aacenc  require libvo_aacenc vo-aacenc/voAAC.h voGetAACEncAPI 
-lvo-aacenc
+enabled libvo_amrwbenc  require libvo_amrwbenc vo-amrwbenc/enc_if.h 
E_IF_init -lvo-amrwbenc
 enabled libvorbis   require  libvorbis vorbis/vorbisenc.h vorbis_info_init 
-lvorbisenc -lvorbis -logg
 enabled libvpx  {
 enabled libvpx_decoder  { check_lib2 vpx/vpx_decoder.h vpx/vp8dx.h 
vpx_codec_dec_init_ver -lvpx ||
@@ -3138,6 +3143,7 @@ echo libspeex enabled  ${libspeex-no}
 echo libtheora enabled ${libtheora-no}
 echo libva enabled ${vaapi-no}
 echo libvo-aacenc support  ${libvo_aacenc-no}
+echo libvo-amrwbenc support${libvo_amrwbenc-no}
 echo libvorbis enabled ${libvorbis-no}
 echo libvpx enabled${libvpx-no}
 echo libx264 enabled   ${libx264-no}
diff --git a/doc/general.texi b/doc/general.texi
index 5d66e42..d4cdc3b 100644
--- a/doc/general.texi
+++ b/doc/general.texi
@@ -588,7 +588,8 @@ following image formats are supported:
 @item ADPCM Yamaha   @tab  X  @tab  X
 @item AMR-NB @tab  E  @tab  X
 @tab encoding supported through external library libopencore-amrnb
-@item AMR-WB @tab @tab  X
+@item AMR-WB @tab  E  @tab  X
+@tab encoding supported through external library libvo-amrwbenc
 @item Apple lossless audio   @tab  X  @tab  X
 @tab QuickTime fourcc 'alac'
 @item Atrac 1@tab @tab  X
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index e9c40e4..1cdae2c 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -569,6 +569,7 @@ OBJS-$(CONFIG_LIBSCHROEDINGER_ENCODER)+= 
libschroedingerenc.o \
 OBJS-$(CONFIG_LIBSPEEX_DECODER)   += libspeexdec.o
 OBJS-$(CONFIG_LIBTHEORA_ENCODER)  += libtheoraenc.o
 OBJS-$(CONFIG_LIBVO_AACENC_ENCODER)   += libvo-aacenc.o mpeg4audio.o
+OBJS-$(CONFIG_LIBVO_AMRWBENC_ENCODER) += libvo-amrwbenc.o
 OBJS-$(CONFIG_LIBVORBIS_ENCODER)  += libvorbis.o vorbis_data.o
 OBJS-$(CONFIG_LIBVPX_DECODER) += libvpxdec.o
 OBJS-$(CONFIG_LIBVPX_ENCODER) += libvpxenc.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index e0323ac..40a7e23 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -367,6 +367,7 @@ void avcodec_register_all(void)
 REGISTER_DECODER (LIBSPEEX, libspeex);
 REGISTER_ENCODER (LIBTHEORA, libtheora);
 REGISTER_ENCODER (LIBVO_AACENC, libvo_aacenc);
+REGISTER_ENCODER (LIBVO_AMRWBENC, libvo_amrwbenc);
 REGISTER_ENCODER (LIBVORBIS, libvorbis);
 REGISTER_ENCDEC  (LIBVPX, 

Re: [libav-devel] [PATCH 1/2] Add an AAC encoder by using the libvo-aacenc library

2011-04-07 Thread Martin Storsjö
On Thu, 7 Apr 2011, Jindřich Makovička wrote:

 On Thu, Apr 7, 2011 at 11:18, Martin Storsjö mar...@martin.st wrote:
 
  +    memset(params, 0, sizeof(params));
  +    params.sampleRate = avctx-sample_rate;
  +    params.bitRate = avctx-bit_rate;
  +    params.nChannels = avctx-channels;
  +    params.adtsUsed = 0;
 
 I think adtsUsed should be set based on CODEC_FLAG_GLOBAL_HEADER ,
 otherwise the AAC output muxed into MPEG-TS won't be playable.
 
 i.e. params.adtsUsed = !(avctx-flags  CODEC_FLAG_GLOBAL_HEADER)

Good point, fixed locally.

Actually, .ts files with data encoded with this encoder, without this fix, 
apprears to work with ffplay at least, but other decoders might of course 
not be so tolerant.

// Martin___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH 1/2] Add an AAC encoder by using the libvo-aacenc library

2011-04-07 Thread Martin Storsjö
On Thu, 7 Apr 2011, Alex Converse wrote:

 On Thu, Apr 7, 2011 at 2:18 AM, Martin Storsjö mar...@martin.st wrote:
  ---
   Changelog                 |    1 +
   configure                 |    6 ++
   libavcodec/Makefile       |    1 +
   libavcodec/allcodecs.c    |    1 +
   libavcodec/libvo-aacenc.c |  132 
  +
   5 files changed, 141 insertions(+), 0 deletions(-)
   create mode 100644 libavcodec/libvo-aacenc.c
 
 
 Perhaps we should remove faac then? Do we need two third party aac encoders?

Probably not, if there aren't any particular features of libfaac that 
vo-aacenc doesn't have, that we care about. libfaac seems to support 
different profiles, and I'm not sure that the visualon code has support 
for that, at least not in the external api at the moment.

// Martin___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH] proto: include os_support.h in network.h

2011-04-07 Thread Martin Storsjö
On Thu, 7 Apr 2011, Luca Barbato wrote:

 Fix compilation on systems without poll()
 ---
  libavformat/network.h |1 +
  1 files changed, 1 insertions(+), 0 deletions(-)
 
 diff --git a/libavformat/network.h b/libavformat/network.h
 index 6943bc6..84a8f53 100644
 --- a/libavformat/network.h
 +++ b/libavformat/network.h
 @@ -22,6 +22,7 @@
  #define AVFORMAT_NETWORK_H
  
  #include config.h
 +#include os_support.h
  
  #if HAVE_WINSOCK2_H
  #include winsock2.h
 -- 
 1.7.4.1

OK

// Martin
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH 1/2] Add an AAC encoder by using the libvo-aacenc library

2011-04-07 Thread Martin Storsjö
On Fri, 8 Apr 2011, Diego Biurrun wrote:

 On Thu, Apr 07, 2011 at 12:18:53PM +0300, Martin Storsjö wrote:
  ---
   Changelog |1 +
   configure |6 ++
   libavcodec/Makefile   |1 +
   libavcodec/allcodecs.c|1 +
   libavcodec/libvo-aacenc.c |  132 
  +
   5 files changed, 141 insertions(+), 0 deletions(-)
   create mode 100644 libavcodec/libvo-aacenc.c
 
 minor bump, docs update

Added

  --- /dev/null
  +++ b/libavcodec/libvo-aacenc.c
  @@ -0,0 +1,132 @@
  +/*
  + * AAC encoder wrapper
  + * Copyright (c) 2010 Martin Storsjo
 
 2011?

I actually wrote this in December, I've only done minor touchups since.

  +#include avcodec.h
  +#include vo-aacenc/voAAC.h
  +#include vo-aacenc/cmnMemory.h
  +#include mpeg4audio.h
 
 Place system headers before local headers, separate by an empty line.

Done

  +typedef struct AACContext {
  +VO_AUDIO_CODECAPI codec_api;
  +VO_HANDLE handle;
  +VO_MEM_OPERATOR mem_operator;
  +VO_CODEC_INIT_USERDATA user_data;
  +} AACContext;
  +
  +static av_cold int aac_encode_init(AVCodecContext *avctx)
  +{
  +AACContext *s = avctx-priv_data;
  +AACENC_PARAM params;
  +int index;
  +
  +memset(params, 0, sizeof(params));
 
 Why not initialize params to 0 instead?

Fixed

  +avctx-coded_frame = avcodec_alloc_frame();
  +avctx-frame_size = 1024;
 
  +s-mem_operator.Alloc = cmnMemAlloc;
  +s-mem_operator.Copy = cmnMemCopy;
  +s-mem_operator.Free = cmnMemFree;
  +s-mem_operator.Set = cmnMemSet;
  +s-mem_operator.Check = cmnMemCheck;
  +s-user_data.memflag = VO_IMF_USERMEMOPERATOR;
  +s-user_data.memData = s-mem_operator;
  +s-codec_api.Init(s-handle, VO_AUDIO_CodingAAC, s-user_data);
 
  +params.sampleRate = avctx-sample_rate;
  +params.bitRate = avctx-bit_rate;
  +params.nChannels = avctx-channels;
  +params.adtsUsed = 0;
 
  +avctx-extradata_size = 2;
  +avctx-extradata = av_mallocz(avctx-extradata_size +
  +  FF_INPUT_BUFFER_PADDING_SIZE);
 
 nit: align the '='

Done

  +static int aac_encode_frame(AVCodecContext *avctx,
  +unsigned char *frame/*out*/,
  +int buf_size, void *data/*in*/)
  +{
  +AACContext *s = avctx-priv_data;
  +VO_CODECBUFFER input, output;
  +VO_AUDIO_OUTPUTINFO output_info;
  +
  +memset(input,   0, sizeof(input));
  +memset(output,  0, sizeof(output));
  +memset(output_info, 0, sizeof(output_info));
 
 same, initialize to 0

Done

// MartinFrom b7a823b2da26d59976464b42d0b7e528cb7980fd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Martin=20Storsj=C3=B6?= mar...@martin.st
Date: Sun, 19 Dec 2010 21:40:23 +0200
Subject: [PATCH 1/2] Add an AAC encoder by using the libvo-aacenc library

---
 Changelog |1 +
 configure |6 ++
 doc/general.texi  |2 +-
 libavcodec/Makefile   |1 +
 libavcodec/allcodecs.c|1 +
 libavcodec/libvo-aacenc.c |  128 +
 libavcodec/version.h  |2 +-
 7 files changed, 139 insertions(+), 2 deletions(-)
 create mode 100644 libavcodec/libvo-aacenc.c

diff --git a/Changelog b/Changelog
index ec09c28..6a255d4 100644
--- a/Changelog
+++ b/Changelog
@@ -83,6 +83,7 @@ version next:
 - Linux framebuffer input device added
 - Chronomaster DFA decoder
 - Mobotix MxPEG decoder
+- AAC encoding via libvo-aacenc
 
 
 version 0.6:
diff --git a/configure b/configure
index 92a809f..8880fba 100755
--- a/configure
+++ b/configure
@@ -178,6 +178,7 @@ External library support:
   --enable-libschroedinger enable Dirac support via libschroedinger [no]
   --enable-libspeexenable Speex decoding via libspeex [no]
   --enable-libtheora   enable Theora encoding via libtheora [no]
+  --enable-libvo-aacencenable AAC encoding via libvo-aacenc [no]
   --enable-libvorbis   enable Vorbis encoding via libvorbis,
native implementation exists [no]
   --enable-libvpx  enable VP8 support via libvpx [no]
@@ -937,6 +938,7 @@ CONFIG_LIST=
 libschroedinger
 libspeex
 libtheora
+libvo_aacenc
 libvorbis
 libvpx
 libx264
@@ -1384,6 +1386,7 @@ libschroedinger_decoder_deps=libschroedinger
 libschroedinger_encoder_deps=libschroedinger
 libspeex_decoder_deps=libspeex
 libtheora_encoder_deps=libtheora
+libvo_aacenc_encoder_deps=libvo_aacenc
 libvorbis_encoder_deps=libvorbis
 libvpx_decoder_deps=libvpx
 libvpx_encoder_deps=libvpx
@@ -2525,6 +2528,7 @@ die_license_disabled nonfree libfaac
 
 die_license_disabled version3 libopencore_amrnb
 die_license_disabled version3 libopencore_amrwb
+die_license_disabled version3 libvo_aacenc
 
 enabled version3  { enabled gpl  enable gplv3 || enable lgplv3; }
 
@@ -2864,6 +2868,7 @@ enabled librtmp require_pkg_config librtmp librtmp/rtmp.h RTMP_Socket

Re: [libav-devel] [PATCH 2/2] Add support for AMR-WB encoding via libvo-amrwbenc

2011-04-07 Thread Martin Storsjö
On Fri, 8 Apr 2011, Diego Biurrun wrote:

 On Thu, Apr 07, 2011 at 12:45:13PM +0300, Martin Storsjö wrote:
  
  --- /dev/null
  +++ b/libavcodec/libvo-amrwbenc.c
  @@ -0,0 +1,126 @@
  +
  +#include avcodec.h
  +#include vo-amrwbenc/enc_if.h
 
 Place system headers before local headers, separate by an empty line.

Done

// MartinFrom da5a20a118336f68ef504d0cf712d18ccaa7ce50 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Martin=20Storsj=C3=B6?= mar...@martin.st
Date: Tue, 29 Dec 2009 16:48:09 +0200
Subject: [PATCH 2/2] Add support for AMR-WB encoding via libvo-amrwbenc

The wrapper code is based on the libamr wrapper removed in SVN rev 19365.
---
 Changelog   |1 +
 configure   |6 ++
 doc/general.texi|3 +-
 libavcodec/Makefile |1 +
 libavcodec/allcodecs.c  |1 +
 libavcodec/libvo-amrwbenc.c |  127 +++
 libavcodec/version.h|2 +-
 7 files changed, 139 insertions(+), 2 deletions(-)
 create mode 100644 libavcodec/libvo-amrwbenc.c

diff --git a/Changelog b/Changelog
index 6a255d4..87ec036 100644
--- a/Changelog
+++ b/Changelog
@@ -84,6 +84,7 @@ version next:
 - Chronomaster DFA decoder
 - Mobotix MxPEG decoder
 - AAC encoding via libvo-aacenc
+- AMR-WB encoding via libvo-amrwbenc
 
 
 version 0.6:
diff --git a/configure b/configure
index 8880fba..c632ce5 100755
--- a/configure
+++ b/configure
@@ -179,6 +179,7 @@ External library support:
   --enable-libspeexenable Speex decoding via libspeex [no]
   --enable-libtheora   enable Theora encoding via libtheora [no]
   --enable-libvo-aacencenable AAC encoding via libvo-aacenc [no]
+  --enable-libvo-amrwbenc  enable AMR-WB encoding via libvo-amrwbenc [no]
   --enable-libvorbis   enable Vorbis encoding via libvorbis,
native implementation exists [no]
   --enable-libvpx  enable VP8 support via libvpx [no]
@@ -939,6 +940,7 @@ CONFIG_LIST=
 libspeex
 libtheora
 libvo_aacenc
+libvo_amrwbenc
 libvorbis
 libvpx
 libx264
@@ -1387,6 +1389,7 @@ libschroedinger_encoder_deps=libschroedinger
 libspeex_decoder_deps=libspeex
 libtheora_encoder_deps=libtheora
 libvo_aacenc_encoder_deps=libvo_aacenc
+libvo_amrwbenc_encoder_deps=libvo_amrwbenc
 libvorbis_encoder_deps=libvorbis
 libvpx_decoder_deps=libvpx
 libvpx_encoder_deps=libvpx
@@ -2529,6 +2532,7 @@ die_license_disabled nonfree libfaac
 die_license_disabled version3 libopencore_amrnb
 die_license_disabled version3 libopencore_amrwb
 die_license_disabled version3 libvo_aacenc
+die_license_disabled version3 libvo_amrwbenc
 
 enabled version3  { enabled gpl  enable gplv3 || enable lgplv3; }
 
@@ -2869,6 +2873,7 @@ enabled libschroedinger  require_pkg_config schroedinger-1.0 schroedinger/schr
 enabled libspeexrequire  libspeex speex/speex.h speex_decoder_init -lspeex
 enabled libtheora   require  libtheora theora/theoraenc.h th_info_init -ltheoraenc -ltheoradec -logg
 enabled libvo_aacenc  require libvo_aacenc vo-aacenc/voAAC.h voGetAACEncAPI -lvo-aacenc
+enabled libvo_amrwbenc  require libvo_amrwbenc vo-amrwbenc/enc_if.h E_IF_init -lvo-amrwbenc
 enabled libvorbis   require  libvorbis vorbis/vorbisenc.h vorbis_info_init -lvorbisenc -lvorbis -logg
 enabled libvpx  {
 enabled libvpx_decoder  { check_lib2 vpx/vpx_decoder.h vpx/vp8dx.h vpx_codec_dec_init_ver -lvpx ||
@@ -3138,6 +3143,7 @@ echo libspeex enabled  ${libspeex-no}
 echo libtheora enabled ${libtheora-no}
 echo libva enabled ${vaapi-no}
 echo libvo-aacenc support  ${libvo_aacenc-no}
+echo libvo-amrwbenc support${libvo_amrwbenc-no}
 echo libvorbis enabled ${libvorbis-no}
 echo libvpx enabled${libvpx-no}
 echo libx264 enabled   ${libx264-no}
diff --git a/doc/general.texi b/doc/general.texi
index a8fab31..2c7949d 100644
--- a/doc/general.texi
+++ b/doc/general.texi
@@ -588,7 +588,8 @@ following image formats are supported:
 @item ADPCM Yamaha   @tab  X  @tab  X
 @item AMR-NB @tab  E  @tab  X
 @tab encoding supported through external library libopencore-amrnb
-@item AMR-WB @tab @tab  X
+@item AMR-WB @tab  E  @tab  X
+@tab encoding supported through external library libvo-amrwbenc
 @item Apple lossless audio   @tab  X  @tab  X
 @tab QuickTime fourcc 'alac'
 @item Atrac 1@tab @tab  X
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index e9c40e4..1cdae2c 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -569,6 +569,7 @@ OBJS-$(CONFIG_LIBSCHROEDINGER_ENCODER)+= libschroedingerenc.o \
 OBJS-$(CONFIG_LIBSPEEX_DECODER)   += libspeexdec.o
 OBJS-$(CONFIG_LIBTHEORA_ENCODER)  += libtheoraenc.o
 OBJS-$(CONFIG_LIBVO_AACENC_ENCODER)   += libvo-aacenc.o mpeg4audio.o
+OBJS-$(CONFIG_LIBVO_AMRWBENC_ENCODER) += libvo-amrwbenc.o
 OBJS-$(CONFIG_LIBVORBIS_ENCODER)  += libvorbis.o

Re: [libav-devel] [PATCH] applehttp: don't use deprecated url_ functions.

2011-04-08 Thread Martin Storsjö
On Fri, 8 Apr 2011, Anton Khirnov wrote:

 ---
  libavformat/applehttp.c |   16 
  1 files changed, 8 insertions(+), 8 deletions(-)
 
 diff --git a/libavformat/applehttp.c b/libavformat/applehttp.c
 index 6c697c5..243f4a6 100644
 --- a/libavformat/applehttp.c
 +++ b/libavformat/applehttp.c
 @@ -113,7 +113,7 @@ static void free_variant_list(AppleHTTPContext *c)
  av_free_packet(var-pkt);
  av_free(var-pb.buffer);
  if (var-input)
 -url_close(var-input);
 +ffurl_close(var-input);
  if (var-ctx) {
  var-ctx-pb = NULL;
  av_close_input_file(var-ctx);
 @@ -291,18 +291,18 @@ reload:
  goto reload;
  }
  
 -ret = url_open(v-input,
 -   v-segments[v-cur_seq_no - v-start_seq_no]-url,
 -   AVIO_RDONLY);
 +ret = ffurl_open(v-input,
 + v-segments[v-cur_seq_no - v-start_seq_no]-url,
 + AVIO_RDONLY);
  if (ret  0)
  return ret;
  }
 -ret = url_read(v-input, buf, buf_size);
 +ret = ffurl_read(v-input, buf, buf_size);
  if (ret  0)
  return ret;
  if (ret  0  ret != AVERROR_EOF)
  return ret;
 -url_close(v-input);
 +ffurl_close(v-input);
  v-input = NULL;
  v-cur_seq_no++;
  
 @@ -435,7 +435,7 @@ static int recheck_discard_flags(AVFormatContext *s, int 
 first)
  av_log(s, AV_LOG_INFO, Now receiving variant %d\n, i);
  } else if (first  !v-cur_needed  v-needed) {
  if (v-input)
 -url_close(v-input);
 +ffurl_close(v-input);
  v-input = NULL;
  v-needed = 0;
  changed = 1;
 @@ -517,7 +517,7 @@ static int applehttp_read_seek(AVFormatContext *s, int 
 stream_index,
  struct variant *var = c-variants[i];
  int64_t pos = 0;
  if (var-input) {
 -url_close(var-input);
 +ffurl_close(var-input);
  var-input = NULL;
  }
  av_free_packet(var-pkt);
 -- 
 1.7.4.1

OK

// Martin
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH 1/2] lavf: rename avf_sdp_create to av_sdp_create.

2011-04-08 Thread Martin Storsjö
On Fri, 8 Apr 2011, Ronald S. Bultje wrote:

 Hi,
 
 On Fri, Apr 8, 2011 at 6:36 AM, Diego Biurrun di...@biurrun.de wrote:
  On Fri, Apr 08, 2011 at 12:24:34PM +0200, Anton Khirnov wrote:
  The new name is more consistent with the rest of the API.
 
  OK
 
 Luca, Martin, any opinions?

Ok with me, but preferrably in two separate patches (renaming the local 
variable separately) as someone else suggested.

// Martin
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH] g722: Return 8 bits per sample for g722 in av_get_bits_per_sample

2011-04-10 Thread Martin Storsjö
This fixes a failing assert in ff_raw_read_header (in
fate-g722dec-1), where bits_per_coded_sample is set using this
function and is required to have a positive value.
---
 libavcodec/utils.c |1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index 12561d0..427e9e4 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -1107,6 +1107,7 @@ int av_get_bits_per_sample(enum CodecID codec_id){
 case CODEC_ID_ADPCM_MS:
 case CODEC_ID_ADPCM_YAMAHA:
 return 4;
+case CODEC_ID_ADPCM_G722:
 case CODEC_ID_PCM_ALAW:
 case CODEC_ID_PCM_MULAW:
 case CODEC_ID_PCM_S8:
-- 
1.7.3.1

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH] g722: Return 8 bits per sample for g722 in av_get_bits_per_sample

2011-04-11 Thread Martin Storsjö
On Sun, 10 Apr 2011, Kostya wrote:

 On Sun, Apr 10, 2011 at 08:39:43PM +0300, Martin Storsjö wrote:
  This fixes a failing assert in ff_raw_read_header (in
  fate-g722dec-1), where bits_per_coded_sample is set using this
  function and is required to have a positive value.
  ---
 
 yes, that looks better

Thanks, pushed.

// Martin___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH 2/2] Add support for AMR-WB encoding via libvo-amrwbenc

2011-04-11 Thread Martin Storsjö
On Mon, 11 Apr 2011, Luca Barbato wrote:

 On 04/08/2011 12:22 AM, Martin Storsjö wrote:
 
  The wrapper code is based on the libamr wrapper removed in SVN rev 19365.
  ---
   Changelog   |1 +
   configure   |6 ++
   doc/general.texi|3 +-
   libavcodec/Makefile |1 +
   libavcodec/allcodecs.c  |1 +
   libavcodec/libvo-amrwbenc.c |  127 
  +++
   libavcodec/version.h|2 +-
 
 
 Looks ok

Pushed

// Martin___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH 1/2] Add an AAC encoder by using the libvo-aacenc library

2011-04-11 Thread Martin Storsjö
On Mon, 11 Apr 2011, Luca Barbato wrote:

 On 04/08/2011 12:21 AM, Martin Storsjö wrote:
   Changelog |1 +
   configure |6 ++
   doc/general.texi  |2 +-
   libavcodec/Makefile   |1 +
   libavcodec/allcodecs.c|1 +
   libavcodec/libvo-aacenc.c |  128 
  +
   libavcodec/version.h  |2 +-
 
 Ok.

Pushed

// Martin___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH 2/2] applehttp: Handle AES-128 encrypted streams

2011-04-12 Thread Martin Storsjö
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.

Is there any use case left that the protocol implementation
handles better than the demuxer?
---
 libavformat/applehttp.c |  108 +-
 libavformat/version.h   |2 +-
 2 files changed, 106 insertions(+), 4 deletions(-)

diff --git a/libavformat/applehttp.c b/libavformat/applehttp.c
index 35759be..3c14ca8 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 unistd.h
@@ -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_RDONLY);
+} 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_RDONLY) == 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);
+

[libav-devel] [PATCH 1/2] Add a protocol handler for AES CBC decryption with PKCS7 padding

2011-04-12 Thread Martin Storsjö
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.
---
 libavformat/Makefile |1 +
 libavformat/allformats.c |1 +
 libavformat/crypto.c |  170 ++
 3 files changed, 172 insertions(+), 0 deletions(-)
 create mode 100644 libavformat/crypto.c

diff --git a/libavformat/Makefile b/libavformat/Makefile
index 719783c..7bb479a 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 9398d34..6b49d21 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -234,6 +234,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 000..83461cb
--- /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, , OFFSET(key), FF_OPT_TYPE_BINARY },
+{iv, , 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)) {
+} else if (av_strstart(uri, crypto:, nested_url)) {
+} else {
+av_log(NULL, AV_LOG_ERROR, Unsupported url %s\n, uri);
+ret = AVERROR(EINVAL);
+goto err;
+}
+
+if (c-keylen  BLOCKSIZE || c-ivlen  BLOCKSIZE) {
+av_log(NULL, AV_LOG_ERROR, Key or IV not set\n);
+ret = AVERROR(EINVAL);
+goto err;
+}
+if (flags  (AVIO_WRONLY | AVIO_RDWR)) {
+av_log(NULL, AV_LOG_ERROR, Only decryption is supported currently\n);
+ret = AVERROR(ENOSYS);
+goto err;
+}
+if ((ret = ffurl_open(c-hd, nested_url, AVIO_RDONLY))  0) {
+av_log(NULL, 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 

Re: [libav-devel] [PATCH] flvdec: Fix support for flvtool2 keyframes based generated index

2011-04-12 Thread Martin Storsjö
On Tue, 12 Apr 2011, Anton Khirnov wrote:

 On Tue, Apr 12, 2011 at 11:41:13AM +0300, Martin Storsjö wrote:
  From: Kharkov Alexander kharkovalexan...@gmail.com
  
  Current keyframes data parser unconditionally rewind metadata to
  the end at the end of function. As result ALL metadata located
  after keyframes index not parsed, and as metadata object can have
  ANY placement inside metadata it can lead to unpredictable result
  (bitrate can not be found, etc.). As result FLV movie will not
  play at all in such situation.
  ---
   libavformat/flvdec.c |3 ++-
   1 files changed, 2 insertions(+), 1 deletions(-)
  
  diff --git a/libavformat/flvdec.c b/libavformat/flvdec.c
  index f27b70c..5438ab0 100644
  --- a/libavformat/flvdec.c
  +++ b/libavformat/flvdec.c
  @@ -136,6 +136,7 @@ static int parse_keyframes_index(AVFormatContext *s, 
  AVIOContext *ioc, AVStream
   int64_t *times = NULL;
   int64_t *filepositions = NULL;
   int ret = 0;
  +int64_t initial_pos = url_ftell(ioc);
 
 avio_tell()

Fixed locally

   
   while (avio_tell(ioc)  max_pos - 2  amf_get_string(ioc, str_val, 
  sizeof(str_val))  0) {
   int64_t* current_array;
  @@ -183,7 +184,7 @@ static int parse_keyframes_index(AVFormatContext *s, 
  AVIOContext *ioc, AVStream
   finish:
   av_freep(times);
   av_freep(filepositions);
  -avio_seek(ioc, max_pos, SEEK_SET);
  +avio_seek(ioc, initial_pos, SEEK_SET);
   return ret;
   }
   
 
 This looks shady. Why should it rewind to the original position?

Well, ideally it should probably seek to the end of the keyframes index 
(but at least not to the end of all the metadata), but since the end of 
the keyframes index isn't trivial to find (since this also is called when 
exiting this function, if any of the allocations failed halfway through), 
this at least seeks back to a good position, where the generic flv amr 
parser can continue to iterate through it all. Or is it trivial to 
calculate the end position of the keyframes index array? My amf knowledge 
is a bit rusty...

Another variant would be not to do any seek in either direction if 
everything went well, at least, but it still requires seeking somewhere if 
something failed.

// Martin___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH] flvdec: Fix support for flvtool2 keyframes based generated index

2011-04-12 Thread Martin Storsjö
On Tue, 12 Apr 2011, Anton Khirnov wrote:

 On Tue, Apr 12, 2011 at 11:58:44AM +0300, Martin Storsjö wrote:
  On Tue, 12 Apr 2011, Anton Khirnov wrote:
  
   On Tue, Apr 12, 2011 at 11:41:13AM +0300, Martin Storsjö wrote:
From: Kharkov Alexander kharkovalexan...@gmail.com

Current keyframes data parser unconditionally rewind metadata to
the end at the end of function. As result ALL metadata located
after keyframes index not parsed, and as metadata object can have
ANY placement inside metadata it can lead to unpredictable result
(bitrate can not be found, etc.). As result FLV movie will not
play at all in such situation.
---
 libavformat/flvdec.c |3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/libavformat/flvdec.c b/libavformat/flvdec.c
index f27b70c..5438ab0 100644
--- a/libavformat/flvdec.c
+++ b/libavformat/flvdec.c
@@ -136,6 +136,7 @@ static int parse_keyframes_index(AVFormatContext 
*s, AVIOContext *ioc, AVStream
 int64_t *times = NULL;
 int64_t *filepositions = NULL;
 int ret = 0;
+int64_t initial_pos = url_ftell(ioc);
   
   avio_tell()
  
  Fixed locally
  
 
 while (avio_tell(ioc)  max_pos - 2  amf_get_string(ioc, 
str_val, sizeof(str_val))  0) {
 int64_t* current_array;
@@ -183,7 +184,7 @@ static int parse_keyframes_index(AVFormatContext 
*s, AVIOContext *ioc, AVStream
 finish:
 av_freep(times);
 av_freep(filepositions);
-avio_seek(ioc, max_pos, SEEK_SET);
+avio_seek(ioc, initial_pos, SEEK_SET);
 return ret;
 }
 
   
   This looks shady. Why should it rewind to the original position?
  
  Well, ideally it should probably seek to the end of the keyframes index 
  (but at least not to the end of all the metadata), but since the end of 
  the keyframes index isn't trivial to find (since this also is called when 
  exiting this function, if any of the allocations failed halfway through), 
  this at least seeks back to a good position, where the generic flv amr 
  parser can continue to iterate through it all. Or is it trivial to 
  calculate the end position of the keyframes index array? My amf knowledge 
  is a bit rusty...
  
 
 Hmm, seems you're right. And here I was thinking that's a nice and not
 at all braindead format.
 
  Another variant would be not to do any seek in either direction if 
  everything went well, at least, but it still requires seeking somewhere if 
  something failed.
  
 
 That sounds like a better idea.

Actually, after re-reading the code, when returning from 
parse_keyframes_index, amf_parse_object will continue to parse the same 
object structure, so we can either do any of the following three:

- Make amf_parse_object not iterate through the object if 
  parse_keyframes_index indicated that everything went well. This requires 
  that we make sure parse_keyframes_index exactly behaves as 
  amr_parse_object would do. Currently it doesn't, if there's some 
  additional unexpected data within the structure (the else break; part 
  within parse_keyframes_index currently). This might not be the only 
  issue, it's only the first thing that came to mind when reading the 
  code.
- Make parse_keyframes_index seek to the end, as it currently does, making 
  amf_parse_object not parse anything more at all, after keyframes have 
  been parsed. Robust, but loses all metadata after the keyframes.
- Make parse_keyframes_indx seek back to where it was before it was 
  called, as this patch does. Simple and robust. Has a slight 
  extra overhead of iterating over the keyframe index twice though.

// Martin___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH 2/3] libvo-*: Don't use deprecated sample format names and enum names

2011-04-12 Thread Martin Storsjö
---
 libavcodec/libvo-aacenc.c   |2 +-
 libavcodec/libvo-amrwbenc.c |2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavcodec/libvo-aacenc.c b/libavcodec/libvo-aacenc.c
index eb34058..205c00e 100644
--- a/libavcodec/libvo-aacenc.c
+++ b/libavcodec/libvo-aacenc.c
@@ -122,7 +122,7 @@ AVCodec ff_libvo_aacenc_encoder = {
 aac_encode_frame,
 aac_encode_close,
 NULL,
-.sample_fmts = (const enum SampleFormat[]){SAMPLE_FMT_S16,SAMPLE_FMT_NONE},
+.sample_fmts = (const enum 
AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE},
 .long_name = NULL_IF_CONFIG_SMALL(libvo-aacenc AAC),
 };
 
diff --git a/libavcodec/libvo-amrwbenc.c b/libavcodec/libvo-amrwbenc.c
index 45da104..661a15d 100644
--- a/libavcodec/libvo-amrwbenc.c
+++ b/libavcodec/libvo-amrwbenc.c
@@ -120,7 +120,7 @@ AVCodec ff_libvo_amrwbenc_encoder = {
 amr_wb_encode_frame,
 amr_wb_encode_close,
 NULL,
-.sample_fmts = (const enum SampleFormat[]){SAMPLE_FMT_S16,SAMPLE_FMT_NONE},
+.sample_fmts = (const enum 
AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE},
 .long_name = NULL_IF_CONFIG_SMALL(libvo-amrwbenc Adaptive Multi-Rate 
   (AMR) Wide-Band),
 };
-- 
1.7.3.1

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH] flvdec: Fix support for flvtool2 keyframes based generated index

2011-04-12 Thread Martin Storsjö
On Tue, 12 Apr 2011, Anton Khirnov wrote:

 On Tue, Apr 12, 2011 at 12:31:28PM +0300, Martin Storsjö wrote:
  On Tue, 12 Apr 2011, Anton Khirnov wrote:
  
   On Tue, Apr 12, 2011 at 11:58:44AM +0300, Martin Storsjö wrote:
On Tue, 12 Apr 2011, Anton Khirnov wrote:

 On Tue, Apr 12, 2011 at 11:41:13AM +0300, Martin Storsjö wrote:
  From: Kharkov Alexander kharkovalexan...@gmail.com
  
  Current keyframes data parser unconditionally rewind metadata to
  the end at the end of function. As result ALL metadata located
  after keyframes index not parsed, and as metadata object can have
  ANY placement inside metadata it can lead to unpredictable result
  (bitrate can not be found, etc.). As result FLV movie will not
  play at all in such situation.
  ---
   libavformat/flvdec.c |3 ++-
   1 files changed, 2 insertions(+), 1 deletions(-)
  
  diff --git a/libavformat/flvdec.c b/libavformat/flvdec.c
  index f27b70c..5438ab0 100644
  --- a/libavformat/flvdec.c
  +++ b/libavformat/flvdec.c
  @@ -136,6 +136,7 @@ static int 
  parse_keyframes_index(AVFormatContext *s, AVIOContext *ioc, AVStream
   int64_t *times = NULL;
   int64_t *filepositions = NULL;
   int ret = 0;
  +int64_t initial_pos = url_ftell(ioc);
 
 avio_tell()

Fixed locally

   
   while (avio_tell(ioc)  max_pos - 2  amf_get_string(ioc, 
  str_val, sizeof(str_val))  0) {
   int64_t* current_array;
  @@ -183,7 +184,7 @@ static int 
  parse_keyframes_index(AVFormatContext *s, AVIOContext *ioc, AVStream
   finish:
   av_freep(times);
   av_freep(filepositions);
  -avio_seek(ioc, max_pos, SEEK_SET);
  +avio_seek(ioc, initial_pos, SEEK_SET);
   return ret;
   }
   
 
 This looks shady. Why should it rewind to the original position?

Well, ideally it should probably seek to the end of the keyframes index 
(but at least not to the end of all the metadata), but since the end of 
the keyframes index isn't trivial to find (since this also is called 
when 
exiting this function, if any of the allocations failed halfway 
through), 
this at least seeks back to a good position, where the generic flv amr 
parser can continue to iterate through it all. Or is it trivial to 
calculate the end position of the keyframes index array? My amf 
knowledge 
is a bit rusty...

   
   Hmm, seems you're right. And here I was thinking that's a nice and not
   at all braindead format.
   
Another variant would be not to do any seek in either direction if 
everything went well, at least, but it still requires seeking somewhere 
if 
something failed.

   
   That sounds like a better idea.
  
  Actually, after re-reading the code, when returning from 
  parse_keyframes_index, amf_parse_object will continue to parse the same 
  object structure, so we can either do any of the following three:
  
  - Make amf_parse_object not iterate through the object if 
parse_keyframes_index indicated that everything went well. This requires 
that we make sure parse_keyframes_index exactly behaves as 
amr_parse_object would do. Currently it doesn't, if there's some 
additional unexpected data within the structure (the else break; part 
within parse_keyframes_index currently). This might not be the only 
issue, it's only the first thing that came to mind when reading the 
code.
  - Make parse_keyframes_index seek to the end, as it currently does, making 
amf_parse_object not parse anything more at all, after keyframes have 
been parsed. Robust, but loses all metadata after the keyframes.
  - Make parse_keyframes_indx seek back to where it was before it was 
called, as this patch does. Simple and robust. Has a slight 
extra overhead of iterating over the keyframe index twice though.
 
 The main problem I see with it is that it doesn't work if the input
 isn't seekable. But i guess it's ok for now and can be solved later if
 someone feels like it.

Pushed.

An approach which doesn't require seekability would be to hook in this 
parsing along the normal recursive amf parsing. That would distribute all 
of the keyframe index parsing all over the place, though. (I didn't follow 
this patchset closely in the beginning, but wasn't that what the author 
did initially?)

// Martin___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH 1/3] libavcodec: Use const enum AVSampleFormat[] in AVCodec initialization

2011-04-12 Thread Martin Storsjö
On Tue, 12 Apr 2011, Diego Biurrun wrote:

 On Tue, Apr 12, 2011 at 10:44:26AM +0300, Martin Storsjö wrote:
  [...]
 
 OK

Pushed this one

// Martin___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH 1/2] Add a protocol handler for AES CBC decryption with PKCS7 padding

2011-04-12 Thread Martin Storsjö
On Tue, 12 Apr 2011, Diego Biurrun wrote:

 On Tue, Apr 12, 2011 at 11:08:13AM +0300, Martin Storsjö wrote:
  This can later be extended to support other AES bit sizes,
  encryption, other crypto algorithms, reading the key from a URL, etc.
  
  --- /dev/null
  +++ b/libavformat/crypto.c
  @@ -0,0 +1,170 @@
  +/*
  + * Decryption protocol handler
  + * Copyright (c) 2011 Martin Storsjo
 
 You skip the umlaut in your own name?

I normally do that within files, yes. Since Janne used the full umlaut 
version in the git author names during the git conversion, I've kept on 
using it there, though, for consistency.

  +#define OFFSET(x) offsetof(CryptoContext, x)
  +static const AVOption options[] = {
  +{key, , OFFSET(key), FF_OPT_TYPE_BINARY },
  +{iv, , OFFSET(iv), FF_OPT_TYPE_BINARY },
  +{NULL}
  +};
  +static const AVClass crypto_class = {
  +crypto, av_default_item_name, options, LIBAVUTIL_VERSION_INT
  +};
 
 That looks quite unreadable unindented and without separating empty
 lines.

Cleaned up locally. Normally, these AVOption lines get very very long, and 
skipping the indentation is a good compromise, but here it sure can be 
cleaned up.

  +if (av_strstart(uri, crypto+, nested_url)) {
  +} else if (av_strstart(uri, crypto:, nested_url)) {
  +} else {
  +av_log(NULL, AV_LOG_ERROR, Unsupported url %s\n, uri);
  +ret = AVERROR(EINVAL);
  +goto err;
  +}
 
 Two empty if blocks?

They indicate the two cases where the url was successfully parsed. 
Simplified into if (!av_strstart()  !av_strstart()) { error; }.

  +c-outptr += size;
  +c-outdata -= size;
 
 extra good alignment karma awaits here

Wooh, extra karma for me \o/

  +c-outdata = BLOCKSIZE * blocks;
  +c-outptr = c-outbuffer;
  +c-indata_used += BLOCKSIZE * blocks;
 
 ditto

Done

  +c-indata -= c-indata_used;
  +c-indata_used = 0;
 
 ditto

Done

// Martin___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH 1/2] Add a protocol handler for AES CBC decryption with PKCS7 padding

2011-04-12 Thread Martin Storsjö
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.
---
 libavformat/Makefile |1 +
 libavformat/allformats.c |1 +
 libavformat/crypto.c |  170 ++
 3 files changed, 172 insertions(+), 0 deletions(-)
 create mode 100644 libavformat/crypto.c

diff --git a/libavformat/Makefile b/libavformat/Makefile
index 719783c..7bb479a 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 9398d34..6b49d21 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -234,6 +234,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 000..16983be
--- /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, , OFFSET(key), FF_OPT_TYPE_BINARY },
+{iv,  , 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(NULL, AV_LOG_ERROR, Unsupported url %s\n, uri);
+ret = AVERROR(EINVAL);
+goto err;
+}
+
+if (c-keylen  BLOCKSIZE || c-ivlen  BLOCKSIZE) {
+av_log(NULL, AV_LOG_ERROR, Key or IV not set\n);
+ret = AVERROR(EINVAL);
+goto err;
+}
+if (flags  (AVIO_WRONLY | AVIO_RDWR)) {
+av_log(NULL, AV_LOG_ERROR, Only decryption is supported currently\n);
+ret = AVERROR(ENOSYS);
+goto err;
+}
+if ((ret = ffurl_open(c-hd, nested_url, AVIO_RDONLY))  0) {
+av_log(NULL, 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,

Re: [libav-devel] [PATCH] flvdec: Only parse keyframe index when the underlying protocol allows seeking

2011-04-12 Thread Martin Storsjö
On Tue, 12 Apr 2011, Luca Barbato wrote:

 On 04/12/2011 12:04 PM, Anton Khirnov wrote:
  On Tue, Apr 12, 2011 at 12:43:23PM +0300, Martin Storsjö wrote:
  From: Michael Niedermayer michae...@gmx.at
 
  Reading the index currently requires seeking.
  ---
   libavformat/flvdec.c |2 +-
   1 files changed, 1 insertions(+), 1 deletions(-)
 
  diff --git a/libavformat/flvdec.c b/libavformat/flvdec.c
  index 62d25c8..1a827fd 100644
  --- a/libavformat/flvdec.c
  +++ b/libavformat/flvdec.c
  @@ -212,7 +212,7 @@ static int amf_parse_object(AVFormatContext *s, 
  AVStream *astream, AVStream *vst
   case AMF_DATA_TYPE_OBJECT: {
   unsigned int keylen;
   
  -if (key  !strcmp(KEYFRAMES_TAG, key)  depth == 1)
  +if (ioc-seekable  key  !strcmp(KEYFRAMES_TAG, key)  
  depth == 1)
   if (parse_keyframes_index(s, ioc, vstream, max_pos)  0)
   return -1;
   
  -- 
  1.7.3.1
 
  
  Ok
 
 s/reading/using. You should be able to read it w/out backward seeks.

Yes, but you can't read the rest of the flv metadata reliably without some 
kind of seek at least (currently a backwards seek), see the other thread 
between me, Anton and Vladimir.

// Martin___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH] flvdec: Only parse keyframe index when the underlying protocol allows seeking

2011-04-12 Thread Martin Storsjö
On Tue, 12 Apr 2011, Luca Barbato wrote:

 On 4/12/11 12:59 PM, Martin Storsjö wrote:
  On Tue, 12 Apr 2011, Anton Khirnov wrote:
  
   On Tue, Apr 12, 2011 at 12:43:23PM +0300, Martin Storsjö wrote:
From: Michael Niedermayermichae...@gmx.at

Reading the index currently requires seeking.
---
  libavformat/flvdec.c |2 +-
  1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/libavformat/flvdec.c b/libavformat/flvdec.c
index 62d25c8..1a827fd 100644
--- a/libavformat/flvdec.c
+++ b/libavformat/flvdec.c
@@ -212,7 +212,7 @@ static int amf_parse_object(AVFormatContext *s,
AVStream *astream, AVStream *vst
  case AMF_DATA_TYPE_OBJECT: {
  unsigned int keylen;

-if (key  !strcmp(KEYFRAMES_TAG, key)  depth == 1)
+if (ioc-seekable  key  !strcmp(KEYFRAMES_TAG, key)
depth == 1)
  if (parse_keyframes_index(s, ioc, vstream, max_pos)
0)
  return -1;

--
1.7.3.1

   
   Ok
  
  Queued.
 
 Dequeue

Ok, dequeing it for now

 there is a simpler solution for that.

No, it isn't fully as simple as you think.

 Right now what we should decide is if we want to error out if we don't have
 enough memory for the index or keep going.
 
 I'd just error out if I cannot parse an element as before.
 
 Here an untested tentative patch, point me to a sample file and I'll 
 make sure it works as should.

As I said in the other thread, if you return from parse_keyframes_index 
without seeking - like you propose, you need to parse in exactly the same 
way as what amf_parse_object does.

There's no requirement on exactly what kind of data you can put in AMF, 
it's a freeform structure as far as I know. The structure currently is 
something like this:

keyframes: { times: [ 1, 2, 3, 4 ], filepositions: [ 100, 200, 300, 400 ] 
}

Now what if the keyframes struct (or object in AMR vocabulary) contains an 
additional key/value, like this:
keyframes: { times: [ ... ], foo: 123, filepositions: [ ... ] }

The generic parser in amf_parse_object handles this - whenever a generic 
data value is expected, it parses that data value according to the type 
identifier (which in most cases just is skipping past the value).

parse_keyframes_index only works with this one fixed structure, if it sees 
something else - anything else than what it expects, it aborts. And then 
the rest of amr_parse_object can't reliably continue parsing the AMF tree, 
since parse_keyframes_index possibly left the reader at any undefined 
position within the keyframes struct.

So if we want to parse this in a simple one-pass fashion, we need to 
integrate the content from parse_keyframes_index into the generic 
recursive parser in amr_parse_object, so that the parser can iterate 
through whatever AMF values there are. Or call into amf_parse_object for 
anything that can be found which isn't specifically parsed by 
parse_keyframes_index.

// Martin___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH] flvdec: Allow parsing keyframes metadata without seeking in most cases

2011-04-12 Thread Martin Storsjö
On Tue, 12 Apr 2011, Luca Barbato wrote:

 On 4/12/11 4:06 PM, Martin Storsjö wrote:
  On Tue, 12 Apr 2011, Luca Barbato wrote:
  
   On 4/12/11 3:47 PM, Martin Storsjö wrote:
Stop the avio input at a point where amf_parse_object can
continue parsing the end of the object seamlessly, when all
data is available.

If unsupported data is encountered within the keyframes object,
try seeking to the start of the keyframes object - if the seek
back was successful, the caller can continue parsing the rest
of the AMF data.
   
   Looks nicely, how to test it?
  
  Mostly by hacking it in different ways to test how it behaves.
  
 
 Thank you =) Seems good.

Ok, queued then.

// Martin___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH 01/12] libopencore-amr: Remove unused code fragments

2011-04-12 Thread Martin Storsjö
This parts are heritage from the encoder part from the old
libamr code removed in SVN rev 19365.
---
 libavcodec/libopencore-amr.c |   11 ---
 1 files changed, 0 insertions(+), 11 deletions(-)

diff --git a/libavcodec/libopencore-amr.c b/libavcodec/libopencore-amr.c
index a7abe26..c11c924 100644
--- a/libavcodec/libopencore-amr.c
+++ b/libavcodec/libopencore-amr.c
@@ -239,20 +239,9 @@ AVCodec ff_libopencore_amrnb_encoder = {
 #include opencore-amrwb/dec_if.h
 #include opencore-amrwb/if_rom.h
 
-static const char wb_bitrate_unsupported[] =
-bitrate not supported: use one of 6.6k, 8.85k, 12.65k, 14.25k, 15.85k, 
18.25k, 19.85k, 23.05k, or 23.85k\n;
-
-/* Common code for fixed and float version*/
-typedef struct AMRWB_bitrates {
-int rate;
-int mode;
-} AMRWB_bitrates;
-
 typedef struct AMRWBContext {
 intframeCount;
 void  *state;
-intmode;
-Word16 allow_dtx;
 } AMRWBContext;
 
 static av_cold int amr_wb_decode_init(AVCodecContext *avctx)
-- 
1.7.3.1

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH 02/12] libopencore-amr: Make the opaque encoder pointer a void*

2011-04-12 Thread Martin Storsjö
---
 libavcodec/libopencore-amr.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/libavcodec/libopencore-amr.c b/libavcodec/libopencore-amr.c
index c11c924..52dfe10 100644
--- a/libavcodec/libopencore-amr.c
+++ b/libavcodec/libopencore-amr.c
@@ -73,7 +73,7 @@ static int getBitrateMode(int bitrate)
 typedef struct AMRContext {
 int   frameCount;
 void *decState;
-int  *enstate;
+void *enstate;
 int   enc_bitrate;
 } AMRContext;
 
-- 
1.7.3.1

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH 03/12] libopencore-amr: Remove a useless debugging variable and commented out logging

2011-04-12 Thread Martin Storsjö
---
 libavcodec/libopencore-amr.c |   15 ---
 1 files changed, 0 insertions(+), 15 deletions(-)

diff --git a/libavcodec/libopencore-amr.c b/libavcodec/libopencore-amr.c
index 52dfe10..0e467a6 100644
--- a/libavcodec/libopencore-amr.c
+++ b/libavcodec/libopencore-amr.c
@@ -71,7 +71,6 @@ static int getBitrateMode(int bitrate)
 }
 
 typedef struct AMRContext {
-int   frameCount;
 void *decState;
 void *enstate;
 int   enc_bitrate;
@@ -81,7 +80,6 @@ static av_cold int amr_nb_decode_init(AVCodecContext *avctx)
 {
 AMRContext *s = avctx-priv_data;
 
-s-frameCount = 0;
 s-decState   = Decoder_Interface_init();
 if (!s-decState) {
 av_log(avctx, AV_LOG_ERROR, Decoder_Interface_init error\r\n);
@@ -117,9 +115,6 @@ static int amr_nb_decode_frame(AVCodecContext *avctx, void 
*data,
 enum Mode dec_mode;
 int packet_size;
 
-/* av_log(NULL, AV_LOG_DEBUG, amr_decode_frame buf=%p buf_size=%d 
frameCount=%d!!\n,
-  buf, buf_size, s-frameCount); */
-
 dec_mode = (buf[0]  3)  0x000F;
 packet_size = block_size[dec_mode] + 1;
 
@@ -129,9 +124,6 @@ static int amr_nb_decode_frame(AVCodecContext *avctx, void 
*data,
 return -1;
 }
 
-s-frameCount++;
-/* av_log(NULL, AV_LOG_DEBUG, packet_size=%d amrData= 0x%X %X %X %X\n,
-  packet_size, amrData[0], amrData[1], amrData[2], amrData[3]); */
 /* call decoder */
 Decoder_Interface_Decode(s-decState, amrData, data, 0);
 *data_size = 160 * 2;
@@ -155,8 +147,6 @@ static av_cold int amr_nb_encode_init(AVCodecContext *avctx)
 {
 AMRContext *s = avctx-priv_data;
 
-s-frameCount = 0;
-
 if (avctx-sample_rate != 8000) {
 av_log(avctx, AV_LOG_ERROR, Only 8000Hz sample rate supported\n);
 return -1;
@@ -207,8 +197,6 @@ static int amr_nb_encode_frame(AVCodecContext *avctx,
 
 written = Encoder_Interface_Encode(s-enstate, s-enc_bitrate, data,
frame, 0);
-/* av_log(NULL, AV_LOG_DEBUG, amr_nb_encode_frame encoded %u bytes, 
bitrate %u, first byte was %#02x\n,
-  written, s-enc_bitrate, frame[0] ); */
 
 return written;
 }
@@ -240,7 +228,6 @@ AVCodec ff_libopencore_amrnb_encoder = {
 #include opencore-amrwb/if_rom.h
 
 typedef struct AMRWBContext {
-intframeCount;
 void  *state;
 } AMRWBContext;
 
@@ -248,7 +235,6 @@ static av_cold int amr_wb_decode_init(AVCodecContext *avctx)
 {
 AMRWBContext *s = avctx-priv_data;
 
-s-frameCount = 0;
 s-state  = D_IF_init();
 
 amr_decode_fix_avctx(avctx);
@@ -285,7 +271,6 @@ static int amr_wb_decode_frame(AVCodecContext *avctx, void 
*data,
 return -1;
 }
 
-s-frameCount++;
 D_IF_decode(s-state, amrData, data, _good_frame);
 *data_size = 320 * 2;
 return packet_size;
-- 
1.7.3.1

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH 06/12] libopencore-amr, libvo-amrwbenc: Return proper error return codes in most places

2011-04-12 Thread Martin Storsjö
---
 libavcodec/libopencore-amr.c |   16 
 libavcodec/libvo-amrwbenc.c  |8 
 2 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/libavcodec/libopencore-amr.c b/libavcodec/libopencore-amr.c
index e6958c9..8a8c18b 100644
--- a/libavcodec/libopencore-amr.c
+++ b/libavcodec/libopencore-amr.c
@@ -90,7 +90,7 @@ static av_cold int amr_nb_decode_init(AVCodecContext *avctx)
 
 if (avctx-channels  1) {
 av_log(avctx, AV_LOG_ERROR, amr_nb: multichannel decoding not 
supported\n);
-return -1;
+return AVERROR(ENOSYS);
 }
 
 return 0;
@@ -121,7 +121,7 @@ static int amr_nb_decode_frame(AVCodecContext *avctx, void 
*data,
 if (packet_size  buf_size) {
 av_log(avctx, AV_LOG_ERROR, amr frame too short (%u, should be %u)\n,
buf_size, packet_size);
-return -1;
+return AVERROR_INVALIDDATA;
 }
 
 /* call decoder */
@@ -149,12 +149,12 @@ static av_cold int amr_nb_encode_init(AVCodecContext 
*avctx)
 
 if (avctx-sample_rate != 8000) {
 av_log(avctx, AV_LOG_ERROR, Only 8000Hz sample rate supported\n);
-return -1;
+return AVERROR(ENOSYS);
 }
 
 if (avctx-channels != 1) {
 av_log(avctx, AV_LOG_ERROR, Only mono supported\n);
-return -1;
+return AVERROR(ENOSYS);
 }
 
 avctx-frame_size  = 160;
@@ -168,7 +168,7 @@ static av_cold int amr_nb_encode_init(AVCodecContext *avctx)
 
 if ((s-enc_bitrate = getBitrateMode(avctx-bit_rate))  0) {
 av_log(avctx, AV_LOG_ERROR, nb_bitrate_unsupported);
-return -1;
+return AVERROR(ENOSYS);
 }
 
 return 0;
@@ -192,7 +192,7 @@ static int amr_nb_encode_frame(AVCodecContext *avctx,
 
 if ((s-enc_bitrate = getBitrateMode(avctx-bit_rate))  0) {
 av_log(avctx, AV_LOG_ERROR, nb_bitrate_unsupported);
-return -1;
+return AVERROR(ENOSYS);
 }
 
 written = Encoder_Interface_Encode(s-enstate, s-enc_bitrate, data,
@@ -236,7 +236,7 @@ static av_cold int amr_wb_decode_init(AVCodecContext *avctx)
 
 if (avctx-channels  1) {
 av_log(avctx, AV_LOG_ERROR, amr_wb: multichannel decoding not 
supported\n);
-return -1;
+return AVERROR(ENOSYS);
 }
 
 return 0;
@@ -263,7 +263,7 @@ static int amr_wb_decode_frame(AVCodecContext *avctx, void 
*data,
 if (packet_size  buf_size) {
 av_log(avctx, AV_LOG_ERROR, amr frame too short (%u, should be %u)\n,
buf_size, packet_size + 1);
-return -1;
+return AVERROR_INVALIDDATA;
 }
 
 D_IF_decode(s-state, amrData, data, _good_frame);
diff --git a/libavcodec/libvo-amrwbenc.c b/libavcodec/libvo-amrwbenc.c
index 661a15d..a5e8f39 100644
--- a/libavcodec/libvo-amrwbenc.c
+++ b/libavcodec/libvo-amrwbenc.c
@@ -65,17 +65,17 @@ static av_cold int amr_wb_encode_init(AVCodecContext *avctx)
 
 if (avctx-sample_rate != 16000) {
 av_log(avctx, AV_LOG_ERROR, Only 16000Hz sample rate supported\n);
-return -1;
+return AVERROR(ENOSYS);
 }
 
 if (avctx-channels != 1) {
 av_log(avctx, AV_LOG_ERROR, Only mono supported\n);
-return -1;
+return AVERROR(ENOSYS);
 }
 
 if ((s-mode = getWBBitrateMode(avctx-bit_rate))  0) {
 av_log(avctx, AV_LOG_ERROR, wb_bitrate_unsupported);
-return -1;
+return AVERROR(ENOSYS);
 }
 
 avctx-frame_size  = 320;
@@ -105,7 +105,7 @@ static int amr_wb_encode_frame(AVCodecContext *avctx,
 
 if ((s-mode = getWBBitrateMode(avctx-bit_rate))  0) {
 av_log(avctx, AV_LOG_ERROR, wb_bitrate_unsupported);
-return -1;
+return AVERROR(ENOSYS);
 }
 size = E_IF_encode(s-state, s-mode, data, frame, s-allow_dtx);
 return size;
-- 
1.7.3.1

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH 3/3] libvo-aacenc: Only produce extradata if the global header flag is set

2011-04-13 Thread Martin Storsjö
On Tue, 12 Apr 2011, Ronald S. Bultje wrote:

 On Tue, Apr 12, 2011 at 3:44 AM, Martin Storsjö mar...@martin.st wrote:
  ---
   libavcodec/libvo-aacenc.c |   18 ++
   1 files changed, 10 insertions(+), 8 deletions(-)
 
  diff --git a/libavcodec/libvo-aacenc.c b/libavcodec/libvo-aacenc.c
  index 3c7dde7..7c1738d 100644
  --- a/libavcodec/libvo-aacenc.c
  +++ b/libavcodec/libvo-aacenc.c
  @@ -62,12 +62,6 @@ static av_cold int aac_encode_init(AVCodecContext *avctx)
          return AVERROR_UNKNOWN;
      }
 
  -    avctx-extradata_size = 2;
  -    avctx-extradata      = av_mallocz(avctx-extradata_size +
  -                                       FF_INPUT_BUFFER_PADDING_SIZE);
  -    if (!avctx-extradata)
  -        return AVERROR(ENOMEM);
  -
      for (index = 0; index  16; index++)
          if (avctx-sample_rate == ff_mpeg4audio_sample_rates[index])
              break;
  @@ -76,8 +70,16 @@ static av_cold int aac_encode_init(AVCodecContext *avctx)
                                      avctx-sample_rate);
          return AVERROR_NOTSUPP;
      }
  -    avctx-extradata[0] = 0x02  3 | index  1;
  -    avctx-extradata[1] = (index  0x01)  7 | avctx-channels  3;
  +    if (avctx-flags  CODEC_FLAG_GLOBAL_HEADER) {
  +        avctx-extradata_size = 2;
  +        avctx-extradata      = av_mallocz(avctx-extradata_size +
  +                                           FF_INPUT_BUFFER_PADDING_SIZE);
  +        if (!avctx-extradata)
  +            return AVERROR(ENOMEM);
  +
  +        avctx-extradata[0] = 0x02  3 | index  1;
  +        avctx-extradata[1] = (index  0x01)  7 | avctx-channels  3;
  +    }
      return 0;
   }
 
 This isn't really what the flag means. If it's data that can be
 discarded at choice, then the flag can be ignored. Formats that don't
 like it, simply don't set extradata.
 
 The idea of the flag is that it creates extradata if set, and then not
 interleave that same data in the bitstream, and if the flag is not
 set, it interleaves that extradata in the bitstream instead. This
 patch doesn't appear to do that, so then it's not necessary...

Yes, we do that already, by enabling ADTS if the global header flag isn't 
set - the ADTS header contains the same data (but is produced by the 
encoder library when the adtsUsed flag is set). But if the global header 
flag isn't set, we perhaps shouldn't produce any extradata at all.

Does anyone else have an opinion, or even better, insight into whether it 
actually is ok to produce extradata even if the global header flag isn't 
set? The data set in the extradata is MPEG4 Audio Specific Config - I 
don't think it makes sense to output such extradata while outputting ADTS 
data.

// Martin___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH 2/2] applehttp: Handle AES-128 encrypted streams

2011-04-13 Thread Martin Storsjö
On Tue, 12 Apr 2011, Ronald S. Bultje wrote:

 Hi,
 
 On Tue, Apr 12, 2011 at 4:08 AM, Martin Storsjö mar...@martin.st wrote:
  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.
 
  Is there any use case left that the protocol implementation
  handles better than the demuxer?
  ---
   libavformat/applehttp.c |  108 
  +-
   libavformat/version.h   |    2 +-
   2 files changed, 106 insertions(+), 4 deletions(-)
 
 So who uses the protocol handler? I forgot how we got to this point of
 having two implementations. Maybe b/c of binary compat you want to
 keep both?

Luca B might be using it at least, perhaps Aviad Rozenhek too.

We got to this point when the demuxer had some issues with real-world 
streams, I had the protocol handler implementation lying around which 
solved the issues (but has a few other drawbacks compared to the demuxer), 
and didn't see how to solve the issues with the demuxer. Now later, I 
think I managed to solve those issues, so as far as I know, the demuxer 
should work quite well now.

 The patch itself looks good to me.

Great, thanks! Any opinions on the crypto protocol in patch 1/2?

// Martin___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH 03/12] libopencore-amr: Remove a useless debugging variable and commented out logging

2011-04-13 Thread Martin Storsjö
On Tue, 12 Apr 2011, Ronald S. Bultje wrote:

 On Tue, Apr 12, 2011 at 5:58 PM, Martin Storsjö mar...@martin.st wrote:
  ---
   libavcodec/libopencore-amr.c |   15 ---
   1 files changed, 0 insertions(+), 15 deletions(-)
 [..]
  diff --git a/libavcodec/libopencore-amr.c b/libavcodec/libopencore-amr.c
 [..]
  -    /* av_log(NULL, AV_LOG_DEBUG, amr_decode_frame buf=%p buf_size=%d 
  frameCount=%d!!\n,
  -              buf, buf_size, s-frameCount); */
 [..]
  -    /* av_log(NULL, AV_LOG_DEBUG, packet_size=%d amrData= 0x%X %X %X 
  %X\n,
  -              packet_size, amrData[0], amrData[1], amrData[2], 
  amrData[3]); */
 [..]
  -    /* av_log(NULL, AV_LOG_DEBUG, amr_nb_encode_frame encoded %u bytes, 
  bitrate %u, first byte was %#02x\n,
 
 How about using av_dlog() for the useful messages?

Done locally.

Queued the ones that were OK and that I was able to apply, rewrote the 
last few.

// Martin___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH 12/12] libopencore-amr, libvo-amrwbenc: Dynamically print the bitrate error message

2011-04-13 Thread Martin Storsjö
On Tue, 12 Apr 2011, Ronald S. Bultje wrote:

 On Tue, Apr 12, 2011 at 5:58 PM, Martin Storsjö mar...@martin.st wrote:
  ---
   libavcodec/libopencore-amr.c |   18 --
   libavcodec/libvo-amrwbenc.c  |   17 ++---
   2 files changed, 14 insertions(+), 21 deletions(-)
 [..]
  -static const char nb_bitrate_unsupported[] =
  -    bitrate not supported: use one of 4.75k, 5.15k, 5.9k, 6.7k, 7.4k, 
  7.95k, 10.2k or 12.2k\n;
 [..]
  +    av_log(log_ctx, AV_LOG_ERROR, bitrate not supported: use one of );
  +    for (i = 0; i  8; i++)
  +        av_log(log_ctx, AV_LOG_ERROR, %d%s, rates[i].rate,
  +                                              i  7 ? ,  : \n);
 
 This isn't a good idea. 2 reasons:
 - 1, what if threading is enabled? Threads could basically log
 interleaved, and that would lead to garbage on the terminal

I'm not sure if there actually is any guarantee that each log line will be 
atomic even if writing with a single av_log(), but there's at least less 
risk for messups. Changed

 - 2, you're printing in decimals instead of in k units now.

Changed.

 What I'd prefer is to keep the nice output that you have now, maybe
 put it in a temporary buffer before printing to the terminal (I know,
 av_hex_dump_log() has that issue also and I have a patch for that
 somewhere). Then lastly, if the bitrate is not right, simply select
 the best one. Don't error out. Just print a warning. And then
 continue.

Changed not to error out but just print a warning, and not to recheck and 
re-warn for each frame unless the user actually changed the bitrate 
inbetween, the rest of the patchset coming up.

// Martin___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH 1/6] libopencore-amr: Remove an unused state variable

2011-04-13 Thread Martin Storsjö
---
 libavcodec/libopencore-amr.c |3 ---
 1 files changed, 0 insertions(+), 3 deletions(-)

diff --git a/libavcodec/libopencore-amr.c b/libavcodec/libopencore-amr.c
index 5110d05..e93fb3d 100644
--- a/libavcodec/libopencore-amr.c
+++ b/libavcodec/libopencore-amr.c
@@ -234,7 +234,6 @@ AVCodec ff_libopencore_amrnb_encoder = {
 #include opencore-amrwb/if_rom.h
 
 typedef struct AMRWBContext {
-intframeCount;
 void  *state;
 } AMRWBContext;
 
@@ -242,7 +241,6 @@ static av_cold int amr_wb_decode_init(AVCodecContext *avctx)
 {
 AMRWBContext *s = avctx-priv_data;
 
-s-frameCount = 0;
 s-state  = D_IF_init();
 
 amr_decode_fix_avctx(avctx);
@@ -278,7 +276,6 @@ static int amr_wb_decode_frame(AVCodecContext *avctx, void 
*data,
 return AVERROR_INVALIDDATA;
 }
 
-s-frameCount++;
 D_IF_decode(s-state, buf, data, _good_frame);
 *data_size = 320 * 2;
 return packet_size;
-- 
1.7.3.1

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH 2/6] libopencore-amr: Convert commented out debug logging into av_dlog

2011-04-13 Thread Martin Storsjö
Also add the avctx as logging context
---
 libavcodec/libopencore-amr.c |   12 ++--
 1 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/libavcodec/libopencore-amr.c b/libavcodec/libopencore-amr.c
index e93fb3d..2945905 100644
--- a/libavcodec/libopencore-amr.c
+++ b/libavcodec/libopencore-amr.c
@@ -116,8 +116,8 @@ static int amr_nb_decode_frame(AVCodecContext *avctx, void 
*data,
 enum Mode dec_mode;
 int packet_size;
 
-/* av_log(NULL, AV_LOG_DEBUG, amr_decode_frame buf=%p buf_size=%d 
frameCount=%d!!\n,
-  buf, buf_size, s-frameCount); */
+av_dlog(avctx, amr_decode_frame buf=%p buf_size=%d frameCount=%d!!\n,
+buf, buf_size, s-frameCount);
 
 dec_mode = (buf[0]  3)  0x000F;
 packet_size = block_size[dec_mode] + 1;
@@ -129,8 +129,8 @@ static int amr_nb_decode_frame(AVCodecContext *avctx, void 
*data,
 }
 
 s-frameCount++;
-/* av_log(NULL, AV_LOG_DEBUG, packet_size=%d buf= 0x%X %X %X %X\n,
-  packet_size, buf[0], buf[1], buf[2], buf[3]); */
+av_dlog(avctx, packet_size=%d buf= 0x%X %X %X %X\n,
+  packet_size, buf[0], buf[1], buf[2], buf[3]);
 /* call decoder */
 Decoder_Interface_Decode(s-decState, buf, data, 0);
 *data_size = 160 * 2;
@@ -206,8 +206,8 @@ static int amr_nb_encode_frame(AVCodecContext *avctx,
 
 written = Encoder_Interface_Encode(s-enstate, s-enc_bitrate, data,
frame, 0);
-/* av_log(NULL, AV_LOG_DEBUG, amr_nb_encode_frame encoded %u bytes, 
bitrate %u, first byte was %#02x\n,
-  written, s-enc_bitrate, frame[0] ); */
+av_dlog(avctx, amr_nb_encode_frame encoded %u bytes, bitrate %u, first 
byte was %#02x\n,
+written, s-enc_bitrate, frame[0]);
 
 return written;
 }
-- 
1.7.3.1

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH 3/6] libopencore-amr, libvo-amrbwenc: Rename variables and functions

2011-04-13 Thread Martin Storsjö
Avoid camel cased names for functions and variables.
---
Okd by Ronald before, but not queued yet due to changes in earlier
patches that this one depends on.

 libavcodec/libopencore-amr.c |   38 +++---
 libavcodec/libvo-amrwbenc.c  |6 +++---
 2 files changed, 22 insertions(+), 22 deletions(-)

diff --git a/libavcodec/libopencore-amr.c b/libavcodec/libopencore-amr.c
index 2945905..b43c32c 100644
--- a/libavcodec/libopencore-amr.c
+++ b/libavcodec/libopencore-amr.c
@@ -50,7 +50,7 @@ typedef struct AMR_bitrates {
 } AMR_bitrates;
 
 /* Match desired bitrate */
-static int getBitrateMode(int bitrate)
+static int get_bitrate_mode(int bitrate)
 {
 /* make the correspondance between bitrate and mode */
 static const AMR_bitrates rates[] = {{ 4750, MR475},
@@ -71,9 +71,9 @@ static int getBitrateMode(int bitrate)
 }
 
 typedef struct AMRContext {
-int   frameCount;
-void *decState;
-void *enstate;
+int   frame_count;
+void *dec_state;
+void *enc_state;
 int   enc_bitrate;
 } AMRContext;
 
@@ -81,9 +81,9 @@ static av_cold int amr_nb_decode_init(AVCodecContext *avctx)
 {
 AMRContext *s = avctx-priv_data;
 
-s-frameCount = 0;
-s-decState   = Decoder_Interface_init();
-if (!s-decState) {
+s-frame_count = 0;
+s-dec_state  = Decoder_Interface_init();
+if (!s-dec_state) {
 av_log(avctx, AV_LOG_ERROR, Decoder_Interface_init error\n);
 return -1;
 }
@@ -102,7 +102,7 @@ static av_cold int amr_nb_decode_close(AVCodecContext 
*avctx)
 {
 AMRContext *s = avctx-priv_data;
 
-Decoder_Interface_exit(s-decState);
+Decoder_Interface_exit(s-dec_state);
 return 0;
 }
 
@@ -116,8 +116,8 @@ static int amr_nb_decode_frame(AVCodecContext *avctx, void 
*data,
 enum Mode dec_mode;
 int packet_size;
 
-av_dlog(avctx, amr_decode_frame buf=%p buf_size=%d frameCount=%d!!\n,
-buf, buf_size, s-frameCount);
+av_dlog(avctx, amr_decode_frame buf=%p buf_size=%d frame_count=%d!!\n,
+buf, buf_size, s-frame_count);
 
 dec_mode = (buf[0]  3)  0x000F;
 packet_size = block_size[dec_mode] + 1;
@@ -128,11 +128,11 @@ static int amr_nb_decode_frame(AVCodecContext *avctx, 
void *data,
 return AVERROR_INVALIDDATA;
 }
 
-s-frameCount++;
+s-frame_count++;
 av_dlog(avctx, packet_size=%d buf= 0x%X %X %X %X\n,
   packet_size, buf[0], buf[1], buf[2], buf[3]);
 /* call decoder */
-Decoder_Interface_Decode(s-decState, buf, data, 0);
+Decoder_Interface_Decode(s-dec_state, buf, data, 0);
 *data_size = 160 * 2;
 
 return packet_size;
@@ -154,7 +154,7 @@ static av_cold int amr_nb_encode_init(AVCodecContext *avctx)
 {
 AMRContext *s = avctx-priv_data;
 
-s-frameCount = 0;
+s-frame_count = 0;
 
 if (avctx-sample_rate != 8000) {
 av_log(avctx, AV_LOG_ERROR, Only 8000Hz sample rate supported\n);
@@ -169,13 +169,13 @@ static av_cold int amr_nb_encode_init(AVCodecContext 
*avctx)
 avctx-frame_size  = 160;
 avctx-coded_frame = avcodec_alloc_frame();
 
-s-enstate=Encoder_Interface_init(0);
-if (!s-enstate) {
+s-enc_state = Encoder_Interface_init(0);
+if (!s-enc_state) {
 av_log(avctx, AV_LOG_ERROR, Encoder_Interface_init error\n);
 return -1;
 }
 
-if ((s-enc_bitrate = getBitrateMode(avctx-bit_rate))  0) {
+if ((s-enc_bitrate = get_bitrate_mode(avctx-bit_rate))  0) {
 av_log(avctx, AV_LOG_ERROR, nb_bitrate_unsupported);
 return AVERROR(ENOSYS);
 }
@@ -187,7 +187,7 @@ static av_cold int amr_nb_encode_close(AVCodecContext 
*avctx)
 {
 AMRContext *s = avctx-priv_data;
 
-Encoder_Interface_exit(s-enstate);
+Encoder_Interface_exit(s-enc_state);
 av_freep(avctx-coded_frame);
 return 0;
 }
@@ -199,12 +199,12 @@ static int amr_nb_encode_frame(AVCodecContext *avctx,
 AMRContext *s = avctx-priv_data;
 int written;
 
-if ((s-enc_bitrate = getBitrateMode(avctx-bit_rate))  0) {
+if ((s-enc_bitrate = get_bitrate_mode(avctx-bit_rate))  0) {
 av_log(avctx, AV_LOG_ERROR, nb_bitrate_unsupported);
 return AVERROR(ENOSYS);
 }
 
-written = Encoder_Interface_Encode(s-enstate, s-enc_bitrate, data,
+written = Encoder_Interface_Encode(s-enc_state, s-enc_bitrate, data,
frame, 0);
 av_dlog(avctx, amr_nb_encode_frame encoded %u bytes, bitrate %u, first 
byte was %#02x\n,
 written, s-enc_bitrate, frame[0]);
diff --git a/libavcodec/libvo-amrwbenc.c b/libavcodec/libvo-amrwbenc.c
index aa89b7f..e55fdc6 100644
--- a/libavcodec/libvo-amrwbenc.c
+++ b/libavcodec/libvo-amrwbenc.c
@@ -33,7 +33,7 @@ typedef struct AMRWBContext {
 intallow_dtx;
 } AMRWBContext;
 
-static int getWBBitrateMode(int bitrate)
+static int get_wb_bitrate_mode(int bitrate)
 {
 /* make the correspondance between bitrate and mode */
 static const int rates[] = {  6600,  8850, 

[libav-devel] [PATCH 4/6] libopencore-amr: Cosmetics: Rewrap and align

2011-04-13 Thread Martin Storsjö
---
Okd by Ronald before, but not queued yet due to changes in earlier
patches that this one depends on.

 libavcodec/libopencore-amr.c |   26 +++---
 1 files changed, 11 insertions(+), 15 deletions(-)

diff --git a/libavcodec/libopencore-amr.c b/libavcodec/libopencore-amr.c
index b43c32c..4d26fc6 100644
--- a/libavcodec/libopencore-amr.c
+++ b/libavcodec/libopencore-amr.c
@@ -53,14 +53,10 @@ typedef struct AMR_bitrates {
 static int get_bitrate_mode(int bitrate)
 {
 /* make the correspondance between bitrate and mode */
-static const AMR_bitrates rates[] = {{ 4750, MR475},
- { 5150, MR515},
- { 5900, MR59},
- { 6700, MR67},
- { 7400, MR74},
- { 7950, MR795},
- {10200, MR102},
- {12200, MR122}, };
+static const AMR_bitrates rates[] = {
+{ 4750, MR475 }, { 5150, MR515 }, {  5900, MR59  }, {  6700, MR67  },
+{ 7400, MR74 },  { 7950, MR795 }, { 10200, MR102 }, { 12200, MR122 }
+};
 int i;
 
 for (i = 0; i  8; i++)
@@ -79,10 +75,10 @@ typedef struct AMRContext {
 
 static av_cold int amr_nb_decode_init(AVCodecContext *avctx)
 {
-AMRContext *s = avctx-priv_data;
+AMRContext *s  = avctx-priv_data;
 
 s-frame_count = 0;
-s-dec_state  = Decoder_Interface_init();
+s-dec_state   = Decoder_Interface_init();
 if (!s-dec_state) {
 av_log(avctx, AV_LOG_ERROR, Decoder_Interface_init error\n);
 return -1;
@@ -111,7 +107,7 @@ static int amr_nb_decode_frame(AVCodecContext *avctx, void 
*data,
 {
 const uint8_t *buf = avpkt-data;
 int buf_size   = avpkt-size;
-AMRContext *s = avctx-priv_data;
+AMRContext *s  = avctx-priv_data;
 static const uint8_t block_size[16] = { 12, 13, 15, 17, 19, 20, 26, 31, 5, 
0, 0, 0, 0, 0, 0, 0 };
 enum Mode dec_mode;
 int packet_size;
@@ -119,7 +115,7 @@ static int amr_nb_decode_frame(AVCodecContext *avctx, void 
*data,
 av_dlog(avctx, amr_decode_frame buf=%p buf_size=%d frame_count=%d!!\n,
 buf, buf_size, s-frame_count);
 
-dec_mode = (buf[0]  3)  0x000F;
+dec_mode= (buf[0]  3)  0x000F;
 packet_size = block_size[dec_mode] + 1;
 
 if (packet_size  buf_size) {
@@ -241,7 +237,7 @@ static av_cold int amr_wb_decode_init(AVCodecContext *avctx)
 {
 AMRWBContext *s = avctx-priv_data;
 
-s-state  = D_IF_init();
+s-state= D_IF_init();
 
 amr_decode_fix_avctx(avctx);
 
@@ -258,7 +254,7 @@ static int amr_wb_decode_frame(AVCodecContext *avctx, void 
*data,
 {
 const uint8_t *buf = avpkt-data;
 int buf_size   = avpkt-size;
-AMRWBContext *s = avctx-priv_data;
+AMRWBContext *s= avctx-priv_data;
 int mode;
 int packet_size;
 static const uint8_t block_size[16] = {18, 24, 33, 37, 41, 47, 51, 59, 61, 
6, 6, 0, 0, 0, 1, 1};
@@ -267,7 +263,7 @@ static int amr_wb_decode_frame(AVCodecContext *avctx, void 
*data,
 /* nothing to do */
 return 0;
 
-mode = (buf[0]  3)  0x000F;
+mode= (buf[0]  3)  0x000F;
 packet_size = block_size[mode];
 
 if (packet_size  buf_size) {
-- 
1.7.3.1

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH 5/6] libopencore-amr, libvo-amrwbenc: Find the closest matching bitrate

2011-04-13 Thread Martin Storsjö
Dynamically print the supported bitrates from the local table,
instead of using a hardcoded log message.
---
 libavcodec/libopencore-amr.c |   36 
 libavcodec/libvo-amrwbenc.c  |   37 -
 2 files changed, 40 insertions(+), 33 deletions(-)

diff --git a/libavcodec/libopencore-amr.c b/libavcodec/libopencore-amr.c
index 4d26fc6..e6216c9 100644
--- a/libavcodec/libopencore-amr.c
+++ b/libavcodec/libopencore-amr.c
@@ -20,6 +20,7 @@
  */
 
 #include avcodec.h
+#include libavutil/avstring.h
 
 static void amr_decode_fix_avctx(AVCodecContext *avctx)
 {
@@ -40,9 +41,6 @@ static void amr_decode_fix_avctx(AVCodecContext *avctx)
 #include opencore-amrnb/interf_dec.h
 #include opencore-amrnb/interf_enc.h
 
-static const char nb_bitrate_unsupported[] =
-bitrate not supported: use one of 4.75k, 5.15k, 5.9k, 6.7k, 7.4k, 7.95k, 
10.2k or 12.2k\n;
-
 /* Common code for fixed and float version*/
 typedef struct AMR_bitrates {
 int   rate;
@@ -50,20 +48,32 @@ typedef struct AMR_bitrates {
 } AMR_bitrates;
 
 /* Match desired bitrate */
-static int get_bitrate_mode(int bitrate)
+static int get_bitrate_mode(int bitrate, void *log_ctx)
 {
 /* make the correspondance between bitrate and mode */
 static const AMR_bitrates rates[] = {
 { 4750, MR475 }, { 5150, MR515 }, {  5900, MR59  }, {  6700, MR67  },
 { 7400, MR74 },  { 7950, MR795 }, { 10200, MR102 }, { 12200, MR122 }
 };
-int i;
+int i, best = -1, min_diff = 0;
+char log_buf[200];
 
-for (i = 0; i  8; i++)
+for (i = 0; i  8; i++) {
 if (rates[i].rate == bitrate)
 return rates[i].mode;
-/* no bitrate matching, return an error */
-return -1;
+if (best  0 || abs(rates[i].rate - bitrate)  min_diff) {
+best = i;
+min_diff = abs(rates[i].rate - bitrate);
+}
+}
+/* no bitrate matching exactly, log a warning */
+snprintf(log_buf, sizeof(log_buf), bitrate not supported: use one of );
+for (i = 0; i  8; i++)
+av_strlcatf(log_buf, sizeof(log_buf), %.2fk, , rates[i].rate/ 
1000.f);
+av_strlcatf(log_buf, sizeof(log_buf), using %.2fk, rates[best].rate / 
1000.f);
+av_log(log_ctx, AV_LOG_WARNING, %s\n, log_buf);
+
+return best;
 }
 
 typedef struct AMRContext {
@@ -171,10 +181,7 @@ static av_cold int amr_nb_encode_init(AVCodecContext 
*avctx)
 return -1;
 }
 
-if ((s-enc_bitrate = get_bitrate_mode(avctx-bit_rate))  0) {
-av_log(avctx, AV_LOG_ERROR, nb_bitrate_unsupported);
-return AVERROR(ENOSYS);
-}
+s-enc_bitrate = get_bitrate_mode(avctx-bit_rate, avctx);
 
 return 0;
 }
@@ -195,10 +202,7 @@ static int amr_nb_encode_frame(AVCodecContext *avctx,
 AMRContext *s = avctx-priv_data;
 int written;
 
-if ((s-enc_bitrate = get_bitrate_mode(avctx-bit_rate))  0) {
-av_log(avctx, AV_LOG_ERROR, nb_bitrate_unsupported);
-return AVERROR(ENOSYS);
-}
+s-enc_bitrate = get_bitrate_mode(avctx-bit_rate, avctx);
 
 written = Encoder_Interface_Encode(s-enc_state, s-enc_bitrate, data,
frame, 0);
diff --git a/libavcodec/libvo-amrwbenc.c b/libavcodec/libvo-amrwbenc.c
index e55fdc6..74caa49 100644
--- a/libavcodec/libvo-amrwbenc.c
+++ b/libavcodec/libvo-amrwbenc.c
@@ -22,10 +22,7 @@
 #include vo-amrwbenc/enc_if.h
 
 #include avcodec.h
-
-static const char wb_bitrate_unsupported[] =
-bitrate not supported: use one of 6.6k, 8.85k, 12.65k, 14.25k, 15.85k, 
-18.25k, 19.85k, 23.05k, or 23.85k\n;
+#include libavutil/avstring.h
 
 typedef struct AMRWBContext {
 void  *state;
@@ -33,18 +30,30 @@ typedef struct AMRWBContext {
 intallow_dtx;
 } AMRWBContext;
 
-static int get_wb_bitrate_mode(int bitrate)
+static int get_wb_bitrate_mode(int bitrate, void *log_ctx)
 {
 /* make the correspondance between bitrate and mode */
 static const int rates[] = {  6600,  8850, 12650, 14250, 15850, 18250,
  19850, 23050, 23850 };
-int i;
+int i, best = -1, min_diff = 0;
+char log_buf[200];
 
-for (i = 0; i  9; i++)
+for (i = 0; i  9; i++) {
 if (rates[i] == bitrate)
 return i;
-/* no bitrate matching, return an error */
-return -1;
+if (best  0 || abs(rates[i] - bitrate)  min_diff) {
+best = i;
+min_diff = abs(rates[i] - bitrate);
+}
+}
+/* no bitrate matching exactly, log a warning */
+snprintf(log_buf, sizeof(log_buf), bitrate not supported: use one of );
+for (i = 0; i  9; i++)
+av_strlcatf(log_buf, sizeof(log_buf), %.2fk, , rates[i]/ 1000.f);
+av_strlcatf(log_buf, sizeof(log_buf), using %.2fk, rates[best] / 1000.f);
+av_log(log_ctx, AV_LOG_WARNING, %s\n, log_buf);
+
+return best;
 }
 
 static av_cold int amr_wb_encode_init(AVCodecContext *avctx)
@@ -61,10 +70,7 @@ static av_cold int 

[libav-devel] [PATCH 6/6] libopencore-amr, libvo-amrwbenc: Only check the bitrate when changed

2011-04-13 Thread Martin Storsjö
Also rename the incorrectly named enc_bitrate to enc_mode, use the
enc_bitrate variable for storing the last chosen bitrate.

This avoids continuous warning log messages if not using an
exactly matching bitrate, while still allowing changing bitrate
at any point.
---
 libavcodec/libopencore-amr.c |   13 +
 libavcodec/libvo-amrwbenc.c  |9 +++--
 2 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/libavcodec/libopencore-amr.c b/libavcodec/libopencore-amr.c
index e6216c9..c8b3a2c 100644
--- a/libavcodec/libopencore-amr.c
+++ b/libavcodec/libopencore-amr.c
@@ -81,6 +81,7 @@ typedef struct AMRContext {
 void *dec_state;
 void *enc_state;
 int   enc_bitrate;
+int   enc_mode;
 } AMRContext;
 
 static av_cold int amr_nb_decode_init(AVCodecContext *avctx)
@@ -181,7 +182,8 @@ static av_cold int amr_nb_encode_init(AVCodecContext *avctx)
 return -1;
 }
 
-s-enc_bitrate = get_bitrate_mode(avctx-bit_rate, avctx);
+s-enc_mode= get_bitrate_mode(avctx-bit_rate, avctx);
+s-enc_bitrate = avctx-bit_rate;
 
 return 0;
 }
@@ -202,12 +204,15 @@ static int amr_nb_encode_frame(AVCodecContext *avctx,
 AMRContext *s = avctx-priv_data;
 int written;
 
-s-enc_bitrate = get_bitrate_mode(avctx-bit_rate, avctx);
+if (s-enc_bitrate != avctx-bit_rate) {
+s-enc_mode= get_bitrate_mode(avctx-bit_rate, avctx);
+s-enc_bitrate = avctx-bit_rate;
+}
 
-written = Encoder_Interface_Encode(s-enc_state, s-enc_bitrate, data,
+written = Encoder_Interface_Encode(s-enc_state, s-enc_mode, data,
frame, 0);
 av_dlog(avctx, amr_nb_encode_frame encoded %u bytes, bitrate %u, first 
byte was %#02x\n,
-written, s-enc_bitrate, frame[0]);
+written, s-enc_mode, frame[0]);
 
 return written;
 }
diff --git a/libavcodec/libvo-amrwbenc.c b/libavcodec/libvo-amrwbenc.c
index 74caa49..162ef01 100644
--- a/libavcodec/libvo-amrwbenc.c
+++ b/libavcodec/libvo-amrwbenc.c
@@ -27,6 +27,7 @@
 typedef struct AMRWBContext {
 void  *state;
 intmode;
+intlast_bitrate;
 intallow_dtx;
 } AMRWBContext;
 
@@ -70,7 +71,8 @@ static av_cold int amr_wb_encode_init(AVCodecContext *avctx)
 return AVERROR(ENOSYS);
 }
 
-s-mode = get_wb_bitrate_mode(avctx-bit_rate, avctx);
+s-mode= get_wb_bitrate_mode(avctx-bit_rate, avctx);
+s-last_bitrate= avctx-bit_rate;
 
 avctx-frame_size  = 320;
 avctx-coded_frame = avcodec_alloc_frame();
@@ -97,7 +99,10 @@ static int amr_wb_encode_frame(AVCodecContext *avctx,
 AMRWBContext *s = avctx-priv_data;
 int size;
 
-s-mode = get_wb_bitrate_mode(avctx-bit_rate, avctx);
+if (s-last_bitrate != avctx-bit_rate) {
+s-mode = get_wb_bitrate_mode(avctx-bit_rate, avctx);
+s-last_bitrate = avctx-bit_rate;
+}
 size = E_IF_encode(s-state, s-mode, data, frame, s-allow_dtx);
 return size;
 }
-- 
1.7.3.1

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH 2/6] libopencore-amr: Convert commented out debug logging into av_dlog

2011-04-13 Thread Martin Storsjö
On Wed, 13 Apr 2011, Diego Biurrun wrote:

 On Wed, Apr 13, 2011 at 11:16:49AM +0300, Martin Storsjö wrote:
  Also add the avctx as logging context
 
 Please end your sentences in periods, even in log messages.

Yeah, noticed after sending the mails, fixed locally already.

// Martin___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH 3/6] libopencore-amr, libvo-amrbwenc: Rename variables and functions

2011-04-13 Thread Martin Storsjö
On Wed, 13 Apr 2011, Diego Biurrun wrote:

 On Wed, Apr 13, 2011 at 11:16:50AM +0300, Martin Storsjö wrote:
  Avoid camel cased names for functions and variables.
 
 camelCase ;)
 
 OK
 
  --- a/libavcodec/libopencore-amr.c
  +++ b/libavcodec/libopencore-amr.c
  @@ -81,9 +81,9 @@ static av_cold int amr_nb_decode_init(AVCodecContext 
  *avctx)
   
  +s-frame_count = 0;
  +s-dec_state  = Decoder_Interface_init();
 
 Please align the '=' while you're at it.
 
 patch OK

Queued with these changes, along with the other ones you OKd.

// Martin___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH 3/3] libvo-aacenc: Only produce extradata if the global header flag is set

2011-04-13 Thread Martin Storsjö
On Wed, 13 Apr 2011, Ronald S. Bultje wrote:

 On Wed, Apr 13, 2011 at 2:49 AM, Martin Storsjö mar...@martin.st wrote:
  On Tue, 12 Apr 2011, Ronald S. Bultje wrote:
  On Tue, Apr 12, 2011 at 3:44 AM, Martin Storsjö mar...@martin.st wrote:
   ---
    libavcodec/libvo-aacenc.c |   18 ++
    1 files changed, 10 insertions(+), 8 deletions(-)
  
   diff --git a/libavcodec/libvo-aacenc.c b/libavcodec/libvo-aacenc.c
   index 3c7dde7..7c1738d 100644
   --- a/libavcodec/libvo-aacenc.c
   +++ b/libavcodec/libvo-aacenc.c
   @@ -62,12 +62,6 @@ static av_cold int aac_encode_init(AVCodecContext 
   *avctx)
           return AVERROR_UNKNOWN;
       }
  
   -    avctx-extradata_size = 2;
   -    avctx-extradata      = av_mallocz(avctx-extradata_size +
   -                                       FF_INPUT_BUFFER_PADDING_SIZE);
   -    if (!avctx-extradata)
   -        return AVERROR(ENOMEM);
   -
       for (index = 0; index  16; index++)
           if (avctx-sample_rate == ff_mpeg4audio_sample_rates[index])
               break;
   @@ -76,8 +70,16 @@ static av_cold int aac_encode_init(AVCodecContext 
   *avctx)
                                       avctx-sample_rate);
           return AVERROR_NOTSUPP;
       }
   -    avctx-extradata[0] = 0x02  3 | index  1;
   -    avctx-extradata[1] = (index  0x01)  7 | avctx-channels  3;
   +    if (avctx-flags  CODEC_FLAG_GLOBAL_HEADER) {
   +        avctx-extradata_size = 2;
   +        avctx-extradata      = av_mallocz(avctx-extradata_size +
   +                                           
   FF_INPUT_BUFFER_PADDING_SIZE);
   +        if (!avctx-extradata)
   +            return AVERROR(ENOMEM);
   +
   +        avctx-extradata[0] = 0x02  3 | index  1;
   +        avctx-extradata[1] = (index  0x01)  7 | avctx-channels  
   3;
   +    }
       return 0;
    }
 
  This isn't really what the flag means. If it's data that can be
  discarded at choice, then the flag can be ignored. Formats that don't
  like it, simply don't set extradata.
 
  The idea of the flag is that it creates extradata if set, and then not
  interleave that same data in the bitstream, and if the flag is not
  set, it interleaves that extradata in the bitstream instead. This
  patch doesn't appear to do that, so then it's not necessary...
 
  Yes, we do that already, by enabling ADTS if the global header flag isn't
  set - the ADTS header contains the same data (but is produced by the
  encoder library when the adtsUsed flag is set). But if the global header
  flag isn't set, we perhaps shouldn't produce any extradata at all.
 
  Does anyone else have an opinion, or even better, insight into whether it
  actually is ok to produce extradata even if the global header flag isn't
  set? The data set in the extradata is MPEG4 Audio Specific Config - I
  don't think it makes sense to output such extradata while outputting ADTS
  data.
 
 I didn't see that you used the same flag elsewhere in this file
 already. Just checked, turns out it's true, so then patch is fine.
 Sorry I didn't see that before.

Thanks - pushed.

// Martin___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH] libvo-* Mention VisualOn in the new codecs' long names

2011-04-13 Thread Martin Storsjö
From: Carl Eugen Hoyos ceho...@ag.or.at

---
 libavcodec/libvo-aacenc.c   |2 +-
 libavcodec/libvo-amrwbenc.c |2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavcodec/libvo-aacenc.c b/libavcodec/libvo-aacenc.c
index 7006d78..0321e77 100644
--- a/libavcodec/libvo-aacenc.c
+++ b/libavcodec/libvo-aacenc.c
@@ -125,6 +125,6 @@ AVCodec ff_libvo_aacenc_encoder = {
 aac_encode_close,
 NULL,
 .sample_fmts = (const enum 
AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE},
-.long_name = NULL_IF_CONFIG_SMALL(libvo-aacenc AAC),
+.long_name = NULL_IF_CONFIG_SMALL(VisualOn libvo-aacenc AAC),
 };
 
diff --git a/libavcodec/libvo-amrwbenc.c b/libavcodec/libvo-amrwbenc.c
index 162ef01..64f19b9 100644
--- a/libavcodec/libvo-amrwbenc.c
+++ b/libavcodec/libvo-amrwbenc.c
@@ -117,7 +117,7 @@ AVCodec ff_libvo_amrwbenc_encoder = {
 amr_wb_encode_close,
 NULL,
 .sample_fmts = (const enum 
AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE},
-.long_name = NULL_IF_CONFIG_SMALL(libvo-amrwbenc Adaptive Multi-Rate 
+.long_name = NULL_IF_CONFIG_SMALL(VisualOn libvo-amrwbenc Adaptive 
Multi-Rate 
   (AMR) Wide-Band),
 };
 
-- 
1.7.3.1

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH] libopencore-amr, libvo-amrwbenc: Allow enabling DTX via private AVOptions

2011-04-13 Thread Martin Storsjö
DTX, discontinuous transmission, allows emitting frames with
comfort noise when no voice is detected in the input audio.
---
 libavcodec/libopencore-amr.c |   15 ++-
 libavcodec/libvo-amrwbenc.c  |   13 -
 2 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/libavcodec/libopencore-amr.c b/libavcodec/libopencore-amr.c
index c8b3a2c..cf8bdbb 100644
--- a/libavcodec/libopencore-amr.c
+++ b/libavcodec/libopencore-amr.c
@@ -21,6 +21,7 @@
 
 #include avcodec.h
 #include libavutil/avstring.h
+#include libavutil/opt.h
 
 static void amr_decode_fix_avctx(AVCodecContext *avctx)
 {
@@ -77,13 +78,24 @@ static int get_bitrate_mode(int bitrate, void *log_ctx)
 }
 
 typedef struct AMRContext {
+AVClass *av_class;
 int   frame_count;
 void *dec_state;
 void *enc_state;
 int   enc_bitrate;
 int   enc_mode;
+int   enc_dtx;
 } AMRContext;
 
+static const AVOption options[] = {
+{ dtx, Allow DTX (generate comfort noise), offsetof(AMRContext, 
enc_dtx), FF_OPT_TYPE_INT, 0, 0, 1, AV_OPT_FLAG_AUDIO_PARAM | 
AV_OPT_FLAG_ENCODING_PARAM },
+{ NULL }
+};
+
+static const AVClass class = {
+libopencore_amrnb, av_default_item_name, options, LIBAVUTIL_VERSION_INT
+};
+
 static av_cold int amr_nb_decode_init(AVCodecContext *avctx)
 {
 AMRContext *s  = avctx-priv_data;
@@ -176,7 +188,7 @@ static av_cold int amr_nb_encode_init(AVCodecContext *avctx)
 avctx-frame_size  = 160;
 avctx-coded_frame = avcodec_alloc_frame();
 
-s-enc_state = Encoder_Interface_init(0);
+s-enc_state = Encoder_Interface_init(s-enc_dtx);
 if (!s-enc_state) {
 av_log(avctx, AV_LOG_ERROR, Encoder_Interface_init error\n);
 return -1;
@@ -228,6 +240,7 @@ AVCodec ff_libopencore_amrnb_encoder = {
 NULL,
 .sample_fmts = (const enum 
AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE},
 .long_name = NULL_IF_CONFIG_SMALL(OpenCORE Adaptive Multi-Rate (AMR) 
Narrow-Band),
+.priv_class = class,
 };
 
 #endif
diff --git a/libavcodec/libvo-amrwbenc.c b/libavcodec/libvo-amrwbenc.c
index 64f19b9..ccd2c72 100644
--- a/libavcodec/libvo-amrwbenc.c
+++ b/libavcodec/libvo-amrwbenc.c
@@ -23,14 +23,25 @@
 
 #include avcodec.h
 #include libavutil/avstring.h
+#include libavutil/opt.h
 
 typedef struct AMRWBContext {
+AVClass *av_class;
 void  *state;
 intmode;
 intlast_bitrate;
 intallow_dtx;
 } AMRWBContext;
 
+static const AVOption options[] = {
+{ dtx, Allow DTX (generate comfort noise), offsetof(AMRWBContext, 
allow_dtx), FF_OPT_TYPE_INT, 0, 0, 1, AV_OPT_FLAG_AUDIO_PARAM | 
AV_OPT_FLAG_ENCODING_PARAM },
+{ NULL }
+};
+
+static const AVClass class = {
+libvo_amrwbenc, av_default_item_name, options, LIBAVUTIL_VERSION_INT
+};
+
 static int get_wb_bitrate_mode(int bitrate, void *log_ctx)
 {
 /* make the correspondance between bitrate and mode */
@@ -78,7 +89,6 @@ static av_cold int amr_wb_encode_init(AVCodecContext *avctx)
 avctx-coded_frame = avcodec_alloc_frame();
 
 s-state = E_IF_init();
-s-allow_dtx = 0;
 
 return 0;
 }
@@ -119,5 +129,6 @@ AVCodec ff_libvo_amrwbenc_encoder = {
 .sample_fmts = (const enum 
AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE},
 .long_name = NULL_IF_CONFIG_SMALL(VisualOn libvo-amrwbenc Adaptive 
Multi-Rate 
   (AMR) Wide-Band),
+.priv_class = class,
 };
 
-- 
1.7.3.1

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH] libvo-*: Fix up the long codec names

2011-04-13 Thread Martin Storsjö
Include VisualOn to clarify the codec name, but remove the
actual library name from the user-friendly description.
Also mention Android, to clarify which VisualOn implementation
this refers to, since they do sell other variants of the same
code, too.
---
 libavcodec/libvo-aacenc.c   |2 +-
 libavcodec/libvo-amrwbenc.c |2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavcodec/libvo-aacenc.c b/libavcodec/libvo-aacenc.c
index 7006d78..f2a19a1 100644
--- a/libavcodec/libvo-aacenc.c
+++ b/libavcodec/libvo-aacenc.c
@@ -125,6 +125,6 @@ AVCodec ff_libvo_aacenc_encoder = {
 aac_encode_close,
 NULL,
 .sample_fmts = (const enum 
AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE},
-.long_name = NULL_IF_CONFIG_SMALL(libvo-aacenc AAC),
+.long_name = NULL_IF_CONFIG_SMALL(Android VisualOn AAC),
 };
 
diff --git a/libavcodec/libvo-amrwbenc.c b/libavcodec/libvo-amrwbenc.c
index 162ef01..d3db5f8 100644
--- a/libavcodec/libvo-amrwbenc.c
+++ b/libavcodec/libvo-amrwbenc.c
@@ -117,7 +117,7 @@ AVCodec ff_libvo_amrwbenc_encoder = {
 amr_wb_encode_close,
 NULL,
 .sample_fmts = (const enum 
AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE},
-.long_name = NULL_IF_CONFIG_SMALL(libvo-amrwbenc Adaptive Multi-Rate 
+.long_name = NULL_IF_CONFIG_SMALL(Android VisualOn Adaptive Multi-Rate 
   (AMR) Wide-Band),
 };
 
-- 
1.7.3.1

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH 5/6] libopencore-amr, libvo-amrwbenc: Find the closest matching bitrate

2011-04-13 Thread Martin Storsjö
On Wed, 13 Apr 2011, Martin Storsjö wrote:

 Dynamically print the supported bitrates from the local table,
 instead of using a hardcoded log message.
 ---
  libavcodec/libopencore-amr.c |   36 
  libavcodec/libvo-amrwbenc.c  |   37 -
  2 files changed, 40 insertions(+), 33 deletions(-)

23:55 wbs BBB-work: do http://patches.libav.org/patch/2241/ and 
http://patches.libav.org/patch/2242/ look ok to you?
00:00 BBB-work wbs: yeah look ok on a quick look

Thus, queued.

// Martin___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH] libavcodec: Bump micro after adding the dtx AVOptions

2011-04-14 Thread Martin Storsjö
On Wed, 13 Apr 2011, Ronald S. Bultje wrote:

 On Wed, Apr 13, 2011 at 6:05 PM, Martin Storsjö mar...@martin.st wrote:
  ---
   libavcodec/version.h |    2 +-
   1 files changed, 1 insertions(+), 1 deletions(-)
 
  diff --git a/libavcodec/version.h b/libavcodec/version.h
  index bad6509..0e2d766 100644
  --- a/libavcodec/version.h
  +++ b/libavcodec/version.h
  @@ -22,7 +22,7 @@
 
   #define LIBAVCODEC_VERSION_MAJOR 52
   #define LIBAVCODEC_VERSION_MINOR 119
  -#define LIBAVCODEC_VERSION_MICRO  0
  +#define LIBAVCODEC_VERSION_MICRO  1
 
 OK.

Thanks, pushed.

// Martin___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH 1/3] introduce side information for AVPacket

2011-04-18 Thread Martin Storsjö
On Mon, 18 Apr 2011, Ronald S. Bultje wrote:

 Hi,
 
 On Mon, Apr 18, 2011 at 1:04 AM, Reinhard Tartler siret...@tauware.de wrote:
  On Fri, Apr 15, 2011 at 18:05:48 (CEST), Luca Barbato wrote:
 
  diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
  index 109d2a4..df4e617 100644
  --- a/libavcodec/avcodec.h
  +++ b/libavcodec/avcodec.h
  @@ -1035,6 +1035,10 @@ typedef struct AVPanScan{
   #define FF_BUFFER_HINTS_PRESERVE 0x04 // User must not alter buffer 
  content.
   #define FF_BUFFER_HINTS_REUSABLE 0x08 // Codec will reuse the buffer 
  (update).
 
  +enum AVPacketSideDataType {
  +    AV_PKT_DATA_PALETTE,
  +};
  +
   typedef struct AVPacket {
       /**
        * Presentation timestamp in AVStream-time_base units; the time at 
  which
  @@ -1057,6 +1061,17 @@ typedef struct AVPacket {
       int   stream_index;
       int   flags;
       /**
  +     * Additional packet data that can be provided by the container.
  +     * Packet can contain several types of side information.
  +     */
  +    struct {
  +        uint8_t *data;
  +        int      size;
  +        enum AVPacketSideDataType type;
  +    } *side_data;
  +    int side_data_elems;
  +
  +    /**
        * Duration of this packet in AVStream-time_base units, 0 if unknown.
        * Equals next_pts - this_pts in presentation order.
        */
 
  To my reading AVPacket is a public struct and therefore cannot be
  extended without bumping major. Did we break ABI with this change?
 
 We can add stuff, but only at the end. We probably broke ABI and this
 should have been moved to the end. We can still do that now.

Not in this struct. AVPackets are allocated statically (e.g. on the stack) 
within calling user applications, and thus adding members even at the end 
requires a major bump.

// Martin___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH] announce the 0.7 beta1 release

2011-04-19 Thread Martin Storsjö
On Tue, 19 Apr 2011, Reinhard Tartler wrote:

 On Tue, Apr 19, 2011 at 12:59:20 (CEST), Luca Barbato wrote:
 
  On 04/17/2011 10:17 PM, Reinhard Tartler wrote:
  [...]
 
  All ok but
 
  +a href=releases/libav-0.7b1.tar.bz2Download bzip2 
  tarball/anbsp;nbsp;
  +a href=releases/libav-0.7b1.tar.bz2.md5MD5/a
  +a href=releases/libav-0.7b1.tar.bz2.sha1SHA1/a
  +a href=releases/libav-0.7b1.tar.bz2.ascPGP signature/abr /
  +a href=releases/libav-0.7b1.tar.gzDownload gzip 
  tarball/anbsp;nbsp;
  +a href=releases/libav-0.7b1.tar.gz.md5MD5/a
  +a href=releases/libav-0.7b1.tar.gz.sha1SHA1/a
  +a href=releases/libav-0.7b1.tar.gz.ascPGP signature/abr /
 
  Mind if I add libav-0.7_beta1.tar.xz ?
 
 No feel free.
 
 In future, it seems to me that 3 version of the tarballs is too
 much. Let's therefore go for .tar.gz and tar.xz in the future. WDYT?

As long as a plain .tar.gz still is available, I don't mind dropping the 
.tar.bz2 for something different.

// Martin
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH] libavformat: Free AVFormatContext-streams

2011-04-20 Thread Martin Storsjö
After switching this from a statically allocated array to a
dynamically allocated one in the major bump, this needs explicit
freeing.
---
Tested that it passes FATE, too.

 libavformat/utils.c |1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/libavformat/utils.c b/libavformat/utils.c
index 0c80ff6..19498b9 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -2564,6 +2564,7 @@ void avformat_free_context(AVFormatContext *s)
 av_freep(s-chapters);
 av_metadata_free(s-metadata);
 av_freep(s-key);
+av_freep(s-streams);
 av_free(s);
 }
 
-- 
1.7.2.5

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH] applehttp: Expose the stream bitrate via metadata

2011-04-20 Thread Martin Storsjö
On Wed, 20 Apr 2011, Ronald S. Bultje wrote:

 Hi,
 
 On Wed, Apr 20, 2011 at 7:49 AM, Martin Storsjö mar...@martin.st wrote:
  This helps callers to intelligently switch between bitrate
  variants.
  ---
   libavformat/applehttp.c |    3 +++
   1 files changed, 3 insertions(+), 0 deletions(-)
 
 Doesn't AVCodecContext have a bit_rate integer for this purpose?

It does, but this is for a slightly different use. The bitrate in 
AVCodecContext is for the actual bitrate of that stream only, while this 
would convey the total bitrate of the whole bitrate variant that this 
stream belongs to. So for that, a different name perhaps would be better, 
like variant_total_bitrate or something similar?

// Martin___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH 1/2] rtp: Add an rtp_ prefix to the dynamic payload handler open/close functions

2011-04-20 Thread Martin Storsjö
This avoids clashes if we internally want to override the global
open function.
---
 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(-)

diff --git a/libavformat/rdt.c b/libavformat/rdt.c
index dfb31d1..1c6452d 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, \
+.rtp_open = rdt_new_context, \
+.rtp_close= rdt_free_context, \
 .parse_packet = rdt_parse_packet \
 }
 
diff --git a/libavformat/rtpdec.h b/libavformat/rtpdec.h
index da53efc..b704c49 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 *(*rtp_open) (void); /// allocate any data needed by the 
rtp parsing for this dynamic data.
+void (*rtp_close)(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..1321a71 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,
+.rtp_open = amr_new_context,
+.rtp_close= 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,
+.rtp_open = amr_new_context,
+.rtp_close= amr_free_context,
 .parse_packet = amr_handle_packet,
 };
 
diff --git a/libavformat/rtpdec_asf.c b/libavformat/rtpdec_asf.c
index a8326cf..c3eb6fe 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, \
+.rtp_open = asfrtp_new_context, \
+.rtp_close= asfrtp_free_context, \
 .parse_packet = asfrtp_parse_packet,   \
 }
 
diff --git a/libavformat/rtpdec_h264.c b/libavformat/rtpdec_h264.c
index 4c9b8ba..c40fcad 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,
+.rtp_open = h264_new_context,
+.rtp_close= h264_free_context,
 .parse_packet = h264_handle_packet
 };
diff --git a/libavformat/rtpdec_latm.c b/libavformat/rtpdec_latm.c
index 5bf4c19..cb9ee4e 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,
+.rtp_open   = latm_new_context,
+

[libav-devel] [PATCH 2/2] Handle unicode file names on windows

2011-04-20 Thread Martin Storsjö
From: Kirill Gavrilov gavr.m...@gmail.com

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.

This doesn't work on Windows 9x, but Win 9x hasn't been supported
since fc5607f8620, without anyone complaining (as far as I know).
If Win9x compatibility is desired, these codepaths can be skipped
at runtime.
---
 cmdutils.c   |   65 ++
 libavformat/os_support.c |   29 
 libavformat/os_support.h |5 +++
 3 files changed, 99 insertions(+), 0 deletions(-)

diff --git a/cmdutils.c b/cmdutils.c
index f1cbd55..bc1a1ff 100644
--- a/cmdutils.c
+++ b/cmdutils.c
@@ -155,6 +155,68 @@ static const OptionDef* find_option(const OptionDef *po, 
const char *name){
 return po;
 }
 
+/**
+ * Prepare command line arguments for executable.
+ * For Windows - perform wide-char to UTF-8 conversion.
+ * Input arguments should be main() function arguments.
+ * @param argc_ptr Arguments number (including executable)
+ * @param argv_ptr Arguments list.
+ */
+static void prepare_app_arguments(int *argc_ptr, char ***argv_ptr);
+
+#if defined(_WIN32)  !defined(__MINGW32CE__)
+/* should be released with av_freep() if needed... */
+static char** win32_argv_utf8 = NULL;
+static int win32_argc = 0;
+
+void prepare_app_arguments(int *argc_ptr, char ***argv_ptr)
+{
+char *argstr_flat;
+wchar_t **argv_w;
+int i, buffsize = 0, offset = 0;
+
+if (win32_argv_utf8) {
+*argc_ptr = win32_argc;
+*argv_ptr = win32_argv_utf8;
+return;
+}
+
+win32_argc = 0;
+argv_w = CommandLineToArgvW(GetCommandLineW(), win32_argc);
+if (win32_argc = 0 || !argv_w)
+return;
+
+/* determine the UTF-8 buffer size (including NULL-termination symbols) */
+for (i = 0; i  win32_argc; i++)
+buffsize += WideCharToMultiByte(CP_UTF8, 0, argv_w[i], -1,
+NULL, 0, NULL, NULL);
+
+win32_argv_utf8 = av_malloc(sizeof(char*) * (win32_argc + 1) + buffsize);
+argstr_flat = win32_argv_utf8 + sizeof(char*) * (win32_argc + 1);
+if (win32_argv_utf8 == NULL) {
+LocalFree(argv_w);
+return;
+}
+
+for (i = 0; i  win32_argc; i++) {
+win32_argv_utf8[i] = argstr_flat[offset];
+offset += WideCharToMultiByte(CP_UTF8, 0, argv_w[i], -1,
+  argstr_flat[offset],
+  buffsize - offset, NULL, NULL);
+}
+win32_argv_utf8[i] = NULL;
+LocalFree(argv_w);
+
+*argc_ptr = win32_argc;
+*argv_ptr = win32_argv_utf8;
+}
+#else
+void prepare_app_arguments(int *argc_ptr, char ***argv_ptr)
+{
+/* nothing to do */
+}
+#endif /* WIN32  !__MINGW32CE__ */
+
 void parse_options(int argc, char **argv, const OptionDef *options,
void (* parse_arg_function)(const char*))
 {
@@ -162,6 +224,9 @@ void parse_options(int argc, char **argv, const OptionDef 
*options,
 int optindex, handleoptions=1;
 const OptionDef *po;
 
+/* perform system-dependent conversions for arguments list */
+prepare_app_arguments(argc, argv);
+
 /* parse options */
 optindex = 1;
 while (optindex  argc) {
diff --git a/libavformat/os_support.c b/libavformat/os_support.c
index 5a3a1bb..68c9086 100644
--- a/libavformat/os_support.c
+++ b/libavformat/os_support.c
@@ -28,6 +28,35 @@
 #include avformat.h
 #include os_support.h
 
+#if defined(_WIN32)  !defined(__MINGW32CE__)
+#include windows.h
+
+#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_malloc(sizeof(wchar_t) * num_chars);
+memset(filename_w, 0,  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 fcntl.h
 #include unistd.h
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;
-- 

[libav-devel] [PATCH 2/2] Handle unicode file names on windows

2011-04-20 Thread Martin Storsjö
From: Kirill Gavrilov gavr.m...@gmail.com

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.

This doesn't work on Windows 9x, but Win 9x hasn't been supported
since fc5607f8620, without anyone complaining (as far as I know).
If Win9x compatibility is desired, these codepaths can be skipped
at runtime.
---
Sorry, the previous one was a broken version, disregard that one.

 cmdutils.c   |   65 ++
 libavformat/os_support.c |   28 +++
 libavformat/os_support.h |5 +++
 3 files changed, 98 insertions(+), 0 deletions(-)

diff --git a/cmdutils.c b/cmdutils.c
index f1cbd55..defe0f6 100644
--- a/cmdutils.c
+++ b/cmdutils.c
@@ -155,6 +155,68 @@ static const OptionDef* find_option(const OptionDef *po, 
const char *name){
 return po;
 }
 
+/**
+ * Prepare command line arguments for executable.
+ * For Windows - perform wide-char to UTF-8 conversion.
+ * Input arguments should be main() function arguments.
+ * @param argc_ptr Arguments number (including executable)
+ * @param argv_ptr Arguments list.
+ */
+static void prepare_app_arguments(int *argc_ptr, char ***argv_ptr);
+
+#if defined(_WIN32)  !defined(__MINGW32CE__)
+/* should be released with av_freep() if needed... */
+static char** win32_argv_utf8 = NULL;
+static int win32_argc = 0;
+
+void prepare_app_arguments(int *argc_ptr, char ***argv_ptr)
+{
+char *argstr_flat;
+wchar_t **argv_w;
+int i, buffsize = 0, offset = 0;
+
+if (win32_argv_utf8) {
+*argc_ptr = win32_argc;
+*argv_ptr = win32_argv_utf8;
+return;
+}
+
+win32_argc = 0;
+argv_w = CommandLineToArgvW(GetCommandLineW(), win32_argc);
+if (win32_argc = 0 || !argv_w)
+return;
+
+/* determine the UTF-8 buffer size (including NULL-termination symbols) */
+for (i = 0; i  win32_argc; i++)
+buffsize += WideCharToMultiByte(CP_UTF8, 0, argv_w[i], -1,
+NULL, 0, NULL, NULL);
+
+win32_argv_utf8 = av_mallocz(sizeof(char*) * (win32_argc + 1) + buffsize);
+argstr_flat = (char*)win32_argv_utf8 + sizeof(char*) * (win32_argc + 
1);
+if (win32_argv_utf8 == NULL) {
+LocalFree(argv_w);
+return;
+}
+
+for (i = 0; i  win32_argc; i++) {
+win32_argv_utf8[i] = argstr_flat[offset];
+offset += WideCharToMultiByte(CP_UTF8, 0, argv_w[i], -1,
+  argstr_flat[offset],
+  buffsize - offset, NULL, NULL);
+}
+win32_argv_utf8[i] = NULL;
+LocalFree(argv_w);
+
+*argc_ptr = win32_argc;
+*argv_ptr = win32_argv_utf8;
+}
+#else
+void prepare_app_arguments(int *argc_ptr, char ***argv_ptr)
+{
+/* nothing to do */
+}
+#endif /* WIN32  !__MINGW32CE__ */
+
 void parse_options(int argc, char **argv, const OptionDef *options,
void (* parse_arg_function)(const char*))
 {
@@ -162,6 +224,9 @@ void parse_options(int argc, char **argv, const OptionDef 
*options,
 int optindex, handleoptions=1;
 const OptionDef *po;
 
+/* perform system-dependent conversions for arguments list */
+prepare_app_arguments(argc, argv);
+
 /* parse options */
 optindex = 1;
 while (optindex  argc) {
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 windows.h
+
+#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 fcntl.h
 #include unistd.h
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 

[libav-devel] [PATCH 2/2] applehttp: Handle AES-128 encrypted streams

2011-04-20 Thread Martin Storsjö
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.

---
This was OKd by Ronald before, but the crypto protocol
patch wasn't OKd yet.

 libavformat/applehttp.c |  108 +-
 libavformat/version.h   |2 +-
 2 files changed, 106 insertions(+), 4 deletions(-)

diff --git a/libavformat/applehttp.c b/libavformat/applehttp.c
index df4494a..4484903 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 unistd.h
@@ -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);
+}
+   

Re: [libav-devel] [PATCH] applehttp: Expose the stream bitrate via metadata

2011-04-20 Thread Martin Storsjö
On Wed, 20 Apr 2011, Martin Storsjö wrote:

 On Wed, 20 Apr 2011, Ronald S. Bultje wrote:
 
  Hi,
  
  On Wed, Apr 20, 2011 at 8:05 AM, Martin Storsjö mar...@martin.st wrote:
   On Wed, 20 Apr 2011, Ronald S. Bultje wrote:
   On Wed, Apr 20, 2011 at 7:49 AM, Martin Storsjö mar...@martin.st wrote:
This helps callers to intelligently switch between bitrate
variants.
---
 libavformat/applehttp.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
  
   Doesn't AVCodecContext have a bit_rate integer for this purpose?
  
   It does, but this is for a slightly different use. The bitrate in
   AVCodecContext is for the actual bitrate of that stream only, while this
   would convey the total bitrate of the whole bitrate variant that this
   stream belongs to. So for that, a different name perhaps would be better,
   like variant_total_bitrate or something similar?
  
  What's the difference?
 
 As Vladimir explained on irc - it's the total bitrate of all streams 
 within the same bitrate variants. If I've got a stream with two variants, 
 100 kbps and 500 kbps, both having audio and video, I'd set 100 kbps as 
 variant_total_bitrate on the two streams from the first variant and 500 
 kbps on the other two. The audio stream bitrate may well be the same, 
 e.g. 32 kbps in both of them, while the video would be 68 in the former 
 and 468 in the latter.
 
 Therefore, when switching, the caller needs to know which streams belong 
 to the same bitrate variant, so that he doesn't accidentally pull from 
 more than one variant at a time, and preferrably also know what their 
 total bitrate is.

To add more to the explanation - currently, the info about which AVStream 
belongs to which variant stream actually is available, it's stored in 
AVStream-id, where the int value says which variant it is a part of - all 
AVStreams with identical id belong together. But someone from XBMC asked 
me yesterday to provide the variant's total bitrate, too, which is useful 
for making better decisions on switching variants.

// Martin___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH] avio: Fix sanity checks in ffurl_read*

2011-04-20 Thread Martin Storsjö
This fixes e.g. reading data over HTTP, where the underlying
socket is set to read/write.
---
 libavformat/avio.c |4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavformat/avio.c b/libavformat/avio.c
index 074d3ee..0702aff 100644
--- a/libavformat/avio.c
+++ b/libavformat/avio.c
@@ -289,14 +289,14 @@ static inline int retry_transfer_wrapper(URLContext *h, 
unsigned char *buf, int
 
 int ffurl_read(URLContext *h, unsigned char *buf, int size)
 {
-if (h-flags  AVIO_FLAG_WRITE)
+if (!(h-flags  AVIO_FLAG_READ))
 return AVERROR(EIO);
 return retry_transfer_wrapper(h, buf, size, 1, h-prot-url_read);
 }
 
 int ffurl_read_complete(URLContext *h, unsigned char *buf, int size)
 {
-if (h-flags  AVIO_FLAG_WRITE)
+if (!(h-flags  AVIO_FLAG_READ))
 return AVERROR(EIO);
 return retry_transfer_wrapper(h, buf, size, size, h-prot-url_read);
 }
-- 
1.7.3.1

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH] applehttp: Expose the stream bitrate via metadata

2011-04-20 Thread Martin Storsjö
On Wed, 20 Apr 2011, Ronald S. Bultje wrote:

 On Wed, Apr 20, 2011 at 9:44 AM, Martin Storsjö mar...@martin.st wrote:
  To add more to the explanation - currently, the info about which AVStream
  belongs to which variant stream actually is available, it's stored in
  AVStream-id, where the int value says which variant it is a part of - all
  AVStreams with identical id belong together. But someone from XBMC asked
  me yesterday to provide the variant's total bitrate, too, which is useful
  for making better decisions on switching variants.
 
 At this point, do we know the bitrates of the individual streams? We
 could simply put that in AVStream-codec-bit_rate and let callers add
 it up...

Only if the chained mpegts demuxer sets it, and it appears it doesn't. 
Also, within the applehttp metadata, there is an explicit bitrate field 
saying what the nominal bitrate of that variant is, we should pass it 
through somewhere at least.

So, would a variant_bitrate metadata key be acceptable? Anton?

// Martin___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH] Makefile: Include dependencies for test tools, too

2011-04-20 Thread Martin Storsjö
This makes seek_test to be rebuilt when its dependencies
has changed. The changes to the dependencies didn't usually matter
in practice, but the introduction of side data in AVPacket required
a recompilation.
---
 Makefile |1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/Makefile b/Makefile
index 0bf04d1..f8e68d6 100644
--- a/Makefile
+++ b/Makefile
@@ -87,6 +87,7 @@ tools/%.o: tools/%.c
$(CC) $(CPPFLAGS) $(CFLAGS) -c $(CC_O) $
 
 -include $(wildcard tools/*.d)
+-include $(wildcard tests/*.d)
 
 ffplay.o: CFLAGS += $(SDL_CFLAGS)
 
-- 
1.7.3.1

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH 1/2] doc: Add some initial docs on the applehttp demuxer

2011-04-20 Thread Martin Storsjö
---
 doc/demuxers.texi |9 +
 1 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/doc/demuxers.texi b/doc/demuxers.texi
index bbdde9c..4168fc1 100644
--- a/doc/demuxers.texi
+++ b/doc/demuxers.texi
@@ -64,4 +64,13 @@ Note that the pattern must not necessarily contain %d or
 ffmpeg -f image2 -i img.jpeg img.png
 @end example
 
+@section applehttp
+
+Apple HTTP Live Streaming demuxer.
+
+This demuxer presents all AVStreams from all variant streams.
+The id field is set to the bitrate variant index number. By setting
+the discard flags on AVStreams (by pressing 'a' or 'v' in ffplay),
+the caller can decide which variant streams to actually receive.
+
 @c man end INPUT DEVICES
-- 
1.7.3.1

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH 2/2] applehttp: Expose the stream bitrate via metadata

2011-04-20 Thread Martin Storsjö
This helps callers to intelligently switch between bitrate
variants.
---
 doc/demuxers.texi   |2 ++
 libavformat/applehttp.c |3 +++
 libavformat/version.h   |2 +-
 3 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/doc/demuxers.texi b/doc/demuxers.texi
index 4168fc1..98f9fde 100644
--- a/doc/demuxers.texi
+++ b/doc/demuxers.texi
@@ -72,5 +72,7 @@ This demuxer presents all AVStreams from all variant streams.
 The id field is set to the bitrate variant index number. By setting
 the discard flags on AVStreams (by pressing 'a' or 'v' in ffplay),
 the caller can decide which variant streams to actually receive.
+The total bitrate of the variant that the stream belongs to is
+available in a metadata key named variant_bitrate.
 
 @c man end INPUT DEVICES
diff --git a/libavformat/applehttp.c b/libavformat/applehttp.c
index df4494a..90b86a8 100644
--- a/libavformat/applehttp.c
+++ b/libavformat/applehttp.c
@@ -367,6 +367,7 @@ static int applehttp_read_header(AVFormatContext *s, 
AVFormatParameters *ap)
 for (i = 0; i  c-n_variants; i++) {
 struct variant *v = c-variants[i];
 AVInputFormat *in_fmt = NULL;
+char bitrate_str[20];
 if (v-n_segments == 0)
 continue;
 
@@ -393,6 +394,7 @@ static int applehttp_read_header(AVFormatContext *s, 
AVFormatParameters *ap)
 if (ret  0)
 goto fail;
 v-stream_offset = stream_offset;
+snprintf(bitrate_str, sizeof(bitrate_str), %d, v-bandwidth);
 /* Create new AVStreams for each stream in this variant */
 for (j = 0; j  v-ctx-nb_streams; j++) {
 AVStream *st = av_new_stream(s, i);
@@ -401,6 +403,7 @@ static int applehttp_read_header(AVFormatContext *s, 
AVFormatParameters *ap)
 goto fail;
 }
 avcodec_copy_context(st-codec, v-ctx-streams[j]-codec);
+av_metadata_set2(st-metadata, variant_bitrate, bitrate_str, 0);
 }
 stream_offset += v-ctx-nb_streams;
 }
diff --git a/libavformat/version.h b/libavformat/version.h
index 0173018..04c5d73 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  0
+#define LIBAVFORMAT_VERSION_MICRO  1
 
 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
LIBAVFORMAT_VERSION_MINOR, \
-- 
1.7.3.1

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH 2/2] applehttp: Expose the stream bitrate via metadata

2011-04-21 Thread Martin Storsjö
On Thu, 21 Apr 2011, Anton Khirnov wrote:

 On Wed, 20 Apr 2011 23:08:40 +0300, Martin Storsjö mar...@martin.st wrote:
  This helps callers to intelligently switch between bitrate
  variants.
  ---
   doc/demuxers.texi   |2 ++
   libavformat/applehttp.c |3 +++
   libavformat/version.h   |2 +-
   3 files changed, 6 insertions(+), 1 deletions(-)
  
  diff --git a/doc/demuxers.texi b/doc/demuxers.texi
  index 4168fc1..98f9fde 100644
  --- a/doc/demuxers.texi
  +++ b/doc/demuxers.texi
  @@ -72,5 +72,7 @@ This demuxer presents all AVStreams from all variant 
  streams.
   The id field is set to the bitrate variant index number. By setting
   the discard flags on AVStreams (by pressing 'a' or 'v' in ffplay),
   the caller can decide which variant streams to actually receive.
  +The total bitrate of the variant that the stream belongs to is
  +available in a metadata key named variant_bitrate.
   
   @c man end INPUT DEVICES
  diff --git a/libavformat/applehttp.c b/libavformat/applehttp.c
  index df4494a..90b86a8 100644
  --- a/libavformat/applehttp.c
  +++ b/libavformat/applehttp.c
  @@ -367,6 +367,7 @@ static int applehttp_read_header(AVFormatContext *s, 
  AVFormatParameters *ap)
   for (i = 0; i  c-n_variants; i++) {
   struct variant *v = c-variants[i];
   AVInputFormat *in_fmt = NULL;
  +char bitrate_str[20];
   if (v-n_segments == 0)
   continue;
   
  @@ -393,6 +394,7 @@ static int applehttp_read_header(AVFormatContext *s, 
  AVFormatParameters *ap)
   if (ret  0)
   goto fail;
   v-stream_offset = stream_offset;
  +snprintf(bitrate_str, sizeof(bitrate_str), %d, v-bandwidth);
   /* Create new AVStreams for each stream in this variant */
   for (j = 0; j  v-ctx-nb_streams; j++) {
   AVStream *st = av_new_stream(s, i);
  @@ -401,6 +403,7 @@ static int applehttp_read_header(AVFormatContext *s, 
  AVFormatParameters *ap)
   goto fail;
   }
   avcodec_copy_context(st-codec, v-ctx-streams[j]-codec);
  +av_metadata_set2(st-metadata, variant_bitrate, 
  bitrate_str, 0);
   }
   stream_offset += v-ctx-nb_streams;
   }
  diff --git a/libavformat/version.h b/libavformat/version.h
  index 0173018..04c5d73 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  0
  +#define LIBAVFORMAT_VERSION_MICRO  1
   
   #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
  LIBAVFORMAT_VERSION_MINOR, \
  -- 
  1.7.3.1
 
 Please add an entry to the list of standard metadata tags in avformat.h.
 
 Otherwise ok.

Updated locally with an entry in avformat.h. Anyone care to ok the 
preceding doc addition? Or just commit this without adding it to the 
demuxer docs, keeping it only in the metadata key list in avformat.h?

// Martin___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH] libavdevice: Define _XOPEN_SOURCE for usleep

2011-04-21 Thread Martin Storsjö
This hopefully fixes build failures on Dragonfly BSD.
---
It's untested in practice, but all other files that use usleep
define _XOPEN_SOURCE=600.

 libavdevice/bktr.c |1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/libavdevice/bktr.c b/libavdevice/bktr.c
index 3e705a0..ab70a1b 100644
--- a/libavdevice/bktr.c
+++ b/libavdevice/bktr.c
@@ -26,6 +26,7 @@
 
 #define _BSD_SOURCE 1
 #define _NETBSD_SOURCE
+#define _XOPEN_SOURCE 600
 
 #include libavformat/avformat.h
 #if HAVE_DEV_BKTR_IOCTL_METEOR_H  HAVE_DEV_BKTR_IOCTL_BT848_H
-- 
1.7.3.1

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH] Provide a fallback version of the libm function trunc

2011-04-21 Thread Martin Storsjö
This fixes compilation on DOS.
---
 configure|2 ++
 libavutil/libm.h |7 +++
 2 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/configure b/configure
index 32c3544..dd44ba4 100755
--- a/configure
+++ b/configure
@@ -1119,6 +1119,7 @@ HAVE_LIST=
 sys_videoio_h
 ten_operands
 threads
+trunc
 truncf
 vfp_args
 VirtualAlloc
@@ -2852,6 +2853,7 @@ check_mathfunc lrint
 check_mathfunc lrintf
 check_mathfunc round
 check_mathfunc roundf
+check_mathfunc trunc
 check_mathfunc truncf
 
 # these are off by default, so fail if requested and not available
diff --git a/libavutil/libm.h b/libavutil/libm.h
index 704bcf9..783f3cd 100644
--- a/libavutil/libm.h
+++ b/libavutil/libm.h
@@ -86,6 +86,13 @@ static av_always_inline av_const float roundf(float x)
 }
 #endif /* HAVE_ROUNDF */
 
+#if !HAVE_TRUNC
+static av_always_inline av_const double trunc(double x)
+{
+return (x  0) ? floor(x) : ceil(x);
+}
+#endif /* HAVE_TRUNC */
+
 #if !HAVE_TRUNCF
 static av_always_inline av_const float truncf(float x)
 {
-- 
1.7.3.1

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH] Mention that DragonFly BSD requires __BSD_VISIBLE set

2011-04-21 Thread Martin Storsjö
Setting this should fix the FATE build failure on DragonFly BSD,
since inet_aton only is visible if __BSD_VISIBLE is set.

Alternatively, a line defining __BSD_VISIBLE=1 could be
added at the top of os_support.c. For FreeBSD, similar lines
are required in libavdevice/bktr.c and libavdevice/oss_audio.c, too.
---
 doc/general.texi |4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/doc/general.texi b/doc/general.texi
index 423402c..5c354ba 100644
--- a/doc/general.texi
+++ b/doc/general.texi
@@ -784,9 +784,9 @@ to configure.
 BSD make will not build Libav, you need to install and use GNU Make
 (@file{gmake}).
 
-@subsubsection FreeBSD
+@subsubsection FreeBSD, DragonFly BSD
 
-FreeBSD will not compile out-of-the-box due to broken system headers.
+FreeBSD and DragonFly BSD will not compile out-of-the-box due to broken system 
headers.
 Passing @code{--extra-cflags=-D__BSD_VISIBLE} to configure will work
 around the problem. This may have unexpected sideeffects, so use it at
 your own risk. If you care about FreeBSD, please make an attempt at
-- 
1.7.3.1

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH] doc: FLV muxing is supported.

2011-04-22 Thread Martin Storsjö
From: Carl Eugen Hoyos ceho...@ag.or.at

---
 doc/general.texi |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/doc/general.texi b/doc/general.texi
index edd5e60..303159e 100644
--- a/doc/general.texi
+++ b/doc/general.texi
@@ -96,7 +96,7 @@ library:
 @tab Only embedded audio is decoded.
 @item FLI/FLC/FLX animation @tab   @tab X
 @tab .fli/.flc files
-@item Flash Video (FLV) @tab   @tab X
+@item Flash Video (FLV) @tab X @tab X
 @tab Macromedia Flash video files
 @item framecrc testing format   @tab X @tab
 @item FunCom ISS@tab   @tab X
-- 
1.7.3.1

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH 1/2] Add a protocol handler for AES CBC decryption with PKCS7 padding

2011-04-22 Thread Martin Storsjö
On Wed, 20 Apr 2011, Anton Khirnov wrote:

 This could use more verbosity, especially if it'll be visible to users
 later on.
 
 Otherwise looks fine to me.

Since both patches had gotten ok's now - pushed.

// Martin
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH 2/2] Handle unicode file names on windows

2011-04-22 Thread Martin Storsjö
On Wed, 20 Apr 2011, Martin Storsjö wrote:

 From: Kirill Gavrilov gavr.m...@gmail.com
 
 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.

Any comments on this cleaned up version of the hacks (except for the minor 
issues Diego pointed out, that I fixed locally)?

// Martin___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH] Mention that DragonFly BSD requires __BSD_VISIBLE set

2011-04-22 Thread Martin Storsjö
On Fri, 22 Apr 2011, Måns Rullgård wrote:

 Ronald S. Bultje rsbul...@gmail.com writes:
 
  Hi,
 
  On Thu, Apr 21, 2011 at 5:48 PM, Martin Storsjö mar...@martin.st wrote:
  Setting this should fix the FATE build failure on DragonFly BSD,
  since inet_aton only is visible if __BSD_VISIBLE is set.
 
  Alternatively, a line defining __BSD_VISIBLE=1 could be
  added at the top of os_support.c. For FreeBSD, similar lines
  are required in libavdevice/bktr.c and libavdevice/oss_audio.c, too.
  ---
   doc/general.texi |    4 ++--
   1 files changed, 2 insertions(+), 2 deletions(-)
 
  Can't we detect BSD subtype automatically and set __BSD_VISIBLE=1
  directly? Mans/Diego?
 
 __BSD_VISIBLE should not be set directly, IIRC.  _BSD_SOURCE is the
 correct symbol to define.  This can be done with add_cppflags -D_BSD_SOURCE
 in the relevant OS sections in configure.

Yes, the *_VISIBLE macros sound like things that shouldn't be set 
manually. Nevertheless, defining _BSD_SOURCE isn't enough for getting the 
inet_aton prototype on DragonFly at least.

// Martin___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH 2/2] Handle unicode file names on windows

2011-04-23 Thread Martin Storsjö
On Sat, 23 Apr 2011, Luca Barbato wrote:

 On 4/20/11 3:26 PM, Martin Storsjö wrote:
  From: Kirill Gavrilovgavr.m...@gmail.com
  
  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.
  
  This doesn't work on Windows 9x, but Win 9x hasn't been supported
  since fc5607f8620, without anyone complaining (as far as I know).
  If Win9x compatibility is desired, these codepaths can be skipped
  at runtime.
 
cmdutils.c   |   65
  ++
 
  diff --git a/cmdutils.c b/cmdutils.c
  index f1cbd55..defe0f6 100644
  --- a/cmdutils.c
  +++ b/cmdutils.c
  @@ -155,6 +155,68 @@ static const OptionDef* find_option(const OptionDef
  *po, const char *name){
return po;
}
  
  +/**
  + * Prepare command line arguments for executable.
  + * For Windows - perform wide-char to UTF-8 conversion.
  + * Input arguments should be main() function arguments.
  + * @param argc_ptr Arguments number (including executable)
  + * @param argv_ptr Arguments list.
  + */
  +static void prepare_app_arguments(int *argc_ptr, char ***argv_ptr);
 
 I'd rather have it somewhere else. The common code should not have system
 specific implementations (that should be applied to stray asm as well as this
 case)

Where would you want this moved, then? A cmdutils_win.c, or a header? For 
stray asm, it's easy to include the right header within #if ARCH_foo. If 
you're ok with keeping all this code in a header, it could be doable, 
otherwise, you'd need to expose the condition (WIN32  !__MINGW32CE__) to 
make, to enable including the file only there. Or always include the file, 
but only compile the actual content within such #ifs within the file.

// Martin___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH] Mention that DragonFly BSD requires __BSD_VISIBLE set

2011-04-23 Thread Martin Storsjö
On Fri, 22 Apr 2011, Måns Rullgård wrote:

 Martin Storsjö mar...@martin.st writes:
 
  On Fri, 22 Apr 2011, Måns Rullgård wrote:
 
  __BSD_VISIBLE should not be set directly, IIRC.  _BSD_SOURCE is the
  correct symbol to define.  This can be done with add_cppflags -D_BSD_SOURCE
  in the relevant OS sections in configure.
 
  Yes, the *_VISIBLE macros sound like things that shouldn't be set 
  manually. Nevertheless, defining _BSD_SOURCE isn't enough for getting the 
  inet_aton prototype on DragonFly at least.
 
 Then find the right thing to define.

As far as I can see, there's nothing else you can define to make it work, 
except undefining _POSIX_C_SOURCE. Here's the relevant parts of 
sys/cdefs.h 
(http://gitweb.dragonflybsd.org/dragonfly.git/blob?f=sys/sys/cdefs.h):

#ifdef _POSIX_C_SOURCE
/* ...
 * Checking exact version of _POSIX_C_SOURCE, never setting __BSD_VISIBLE 
 */
#else
/* ...
 * If a program mistakenly defines _ANSI_SOURCE and some other macro such 
as
 * _POSIX_C_SOURCE, we will assume that it wants the broader compilation
 * environment (and in fact we will never get here).
 */
#ifdef _ANSI_SOURCE /* Hide almost everything. */
#define __POSIX_VISIBLE 0
#define __XSI_VISIBLE   0
#define __BSD_VISIBLE   0
#define __ISO_C_VISIBLE 1990
#elif defined(_C99_SOURCE)  /* Localism to specify strict C99 env. */
#define __POSIX_VISIBLE 0
#define __XSI_VISIBLE   0
#define __BSD_VISIBLE   0
#define __ISO_C_VISIBLE 1999
#else   /* Default environment: show everything. 
*/
#define __POSIX_VISIBLE 200112
#define __XSI_VISIBLE   600
#define __BSD_VISIBLE   1
#define __ISO_C_VISIBLE 1999
#endif

#endif

This is the only place __BSD_VISIBLE is set under /usr/include as far as I 
can see, and as long as _POSIX_C_SOURCE is defined, it will never be 
defined. And __BSD_VISIBLE is required for inet_aton to be visible: 
http://gitweb.dragonflybsd.org/dragonfly.git/blob?f=include/arpa/inet.h

Didn't perform the same check for FreeBSD yet, though...

// Martin___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH 3/3] aacenc: Fix whitespace after last commit.

2011-04-23 Thread Martin Storsjö
On Tue, 5 Apr 2011, Kostya wrote:

 On Tue, Apr 05, 2011 at 01:05:24AM -0600, Nathan Caldwell wrote:
  ---
   libavcodec/aacpsy.c |   23 +--
   1 files changed, 13 insertions(+), 10 deletions(-)
  
  diff --git a/libavcodec/aacpsy.c b/libavcodec/aacpsy.c
  index 413d364..0944c34 100644
  --- a/libavcodec/aacpsy.c
  +++ b/libavcodec/aacpsy.c
  @@ -98,9 +98,9 @@ enum {
* information for single band used by 3GPP TS26.403-inspired 
  psychoacoustic model
*/
   typedef struct AacPsyBand{
  -float energy;/// band energy
  -float thr;   /// energy threshold
  -float thr_quiet; /// threshold in quiet
  +float energy;   /// band energy
  +float thr;  /// energy threshold
  +float thr_quiet;/// threshold in quiet
   float nz_lines; /// number of non-zero spectral lines
   float active_lines; /// number of active spectral lines
   float pe;   /// perceptual entropy
  @@ -556,43 +556,46 @@ static void psy_3gpp_analyze(FFPsyContext *ctx, int 
  channel,
   float desired_bits, desired_pe, delta_pe, reduction, spread_en[128] = 
  {0};
   float a = 0.0f, active_lines = 0.0f, norm_fac = 0.0f;
   float pe = pctx-chan_bitrate  32000 ? 0.0f : FFMAX(50.0f, 100.0f - 
  pctx-chan_bitrate * 100.0f / 32000.0f);
  -const int  num_bands  = ctx-num_bands[wi-num_windows == 8];
  -const uint8_t *band_sizes = ctx-bands[wi-num_windows == 8];
  -AacPsyCoeffs  *coeffs = pctx-psy_coef[wi-num_windows == 8];
  +const int  num_bands   = ctx-num_bands[wi-num_windows == 8];
  +const uint8_t *band_sizes  = ctx-bands[wi-num_windows == 8];
  +AacPsyCoeffs  *coeffs  = pctx-psy_coef[wi-num_windows == 8];
   const float avoid_hole_thr = wi-num_windows == 8 ? 
  PSY_3GPP_AH_THR_SHORT : PSY_3GPP_AH_THR_LONG;
   
   //calculate energies, initial thresholds and related values - 5.4.2 
  Threshold Calculation
   for (w = 0; w  wi-num_windows*16; w += 16) {
   for (g = 0; g  num_bands; g++) {
   AacPsyBand *band = pch-band[w+g];
  +
   float form_factor = 0.0f;
   band-energy = 0.0f;
   for (i = 0; i  band_sizes[g]; i++) {
   band-energy += coefs[start+i] * coefs[start+i];
   form_factor  += sqrtf(fabs(coefs[start+i]));
   }
  -band-thr = band-energy * 0.001258925f;
  +band-thr  = band-energy * 0.001258925f;
   band-nz_lines = form_factor / powf(band-energy / 
  band_sizes[g], 0.25f);
   
  -start+= band_sizes[g];
  +start += band_sizes[g];
   }
   }
   //modify thresholds and energies - spread, threshold in quiet, 
  pre-echo control
   for (w = 0; w  wi-num_windows*16; w += 16) {
   AacPsyBand *bands = pch-band[w];
  +
   //5.4.2.3 Spreading  5.4.3 Spreaded Energy Calculation
   spread_en[0] = bands[0].energy;
   for (g = 1; g  num_bands; g++) {
  -bands[g].thr = FFMAX(bands[g].thr, bands[g-1].thr * 
  coeffs[g].spread_hi[0]);
  +bands[g].thr   = FFMAX(bands[g].thr,bands[g-1].thr * 
  coeffs[g].spread_hi[0]);
   spread_en[w+g] = FFMAX(bands[g].energy, spread_en[w+g-1] * 
  coeffs[g].spread_hi[1]);
   }
   for (g = num_bands - 2; g = 0; g--) {
  -bands[g].thr = FFMAX(bands[g].thr, bands[g+1].thr * 
  coeffs[g].spread_low[0]);
  +bands[g].thr   = FFMAX(bands[g].thr,   bands[g+1].thr * 
  coeffs[g].spread_low[0]);
   spread_en[w+g] = FFMAX(spread_en[w+g], spread_en[w+g+1] * 
  coeffs[g].spread_low[1]);
   }
   //5.4.2.4 Threshold in quiet
   for (g = 0; g  num_bands; g++) {
   AacPsyBand *band = bands[g];
  +
   band-thr_quiet = band-thr = FFMAX(band-thr, coeffs[g].ath);
   //5.4.2.5 Pre-echo control
   if (!(wi-window_type[0] == LONG_STOP_SEQUENCE || 
  (wi-window_type[1] == LONG_START_SEQUENCE  !w)))
  -- 
 
 obviously ok

Pushed

// Martin
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH 2/2] Handle unicode file names on windows

2011-04-23 Thread Martin Storsjö
From: Kirill Gavrilov gavr.m...@gmail.com

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.
---
 cmdutils.c   |4 ++
 cmdutils_args.h  |   86 ++
 libavformat/os_support.c |   28 +++
 libavformat/os_support.h |5 +++
 libavformat/version.h|2 +-
 5 files changed, 124 insertions(+), 1 deletions(-)
 create mode 100644 cmdutils_args.h

diff --git a/cmdutils.c b/cmdutils.c
index f1cbd55..c6128e2 100644
--- a/cmdutils.c
+++ b/cmdutils.c
@@ -47,6 +47,7 @@
 #if HAVE_SYS_RESOURCE_H
 #include sys/resource.h
 #endif
+#include cmdutils_args.h
 
 const char **opt_names;
 const char **opt_values;
@@ -162,6 +163,9 @@ void parse_options(int argc, char **argv, const OptionDef 
*options,
 int optindex, handleoptions=1;
 const OptionDef *po;
 
+/* perform system-dependent conversions for arguments list */
+prepare_app_arguments(argc, argv);
+
 /* parse options */
 optindex = 1;
 while (optindex  argc) {
diff --git a/cmdutils_args.h b/cmdutils_args.h
new file mode 100644
index 000..4eccdbb
--- /dev/null
+++ b/cmdutils_args.h
@@ -0,0 +1,86 @@
+/*
+ * Character set conversion for command line arguments
+ * Copyright (c) 2011 Kirill Gavrilov
+ *
+ * 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
+ */
+
+#ifndef CMDUTILS_ARGS_H
+#define CMDUTILS_ARGS_H
+
+#if defined(_WIN32)  !defined(__MINGW32CE__)
+#include windows.h
+/* Will be leaked on exit */
+static char** win32_argv_utf8 = NULL;
+static int win32_argc = 0;
+
+/**
+ * Prepare command line arguments for executable.
+ * For Windows - perform wide-char to UTF-8 conversion.
+ * Input arguments should be main() function arguments.
+ * @param argc_ptr Arguments number (including executable)
+ * @param argv_ptr Arguments list.
+ */
+static void prepare_app_arguments(int *argc_ptr, char ***argv_ptr)
+{
+char *argstr_flat;
+wchar_t **argv_w;
+int i, buffsize = 0, offset = 0;
+
+if (win32_argv_utf8) {
+*argc_ptr = win32_argc;
+*argv_ptr = win32_argv_utf8;
+return;
+}
+
+win32_argc = 0;
+argv_w = CommandLineToArgvW(GetCommandLineW(), win32_argc);
+if (win32_argc = 0 || !argv_w)
+return;
+
+/* determine the UTF-8 buffer size (including NULL-termination symbols) */
+for (i = 0; i  win32_argc; i++)
+buffsize += WideCharToMultiByte(CP_UTF8, 0, argv_w[i], -1,
+NULL, 0, NULL, NULL);
+
+win32_argv_utf8 = av_mallocz(sizeof(char*) * (win32_argc + 1) + buffsize);
+argstr_flat = (char*)win32_argv_utf8 + sizeof(char*) * (win32_argc + 
1);
+if (win32_argv_utf8 == NULL) {
+LocalFree(argv_w);
+return;
+}
+
+for (i = 0; i  win32_argc; i++) {
+win32_argv_utf8[i] = argstr_flat[offset];
+offset += WideCharToMultiByte(CP_UTF8, 0, argv_w[i], -1,
+  argstr_flat[offset],
+  buffsize - offset, NULL, NULL);
+}
+win32_argv_utf8[i] = NULL;
+LocalFree(argv_w);
+
+*argc_ptr = win32_argc;
+*argv_ptr = win32_argv_utf8;
+}
+#else
+static inline void prepare_app_arguments(int *argc_ptr, char ***argv_ptr)
+{
+/* nothing to do */
+}
+#endif /* WIN32  !__MINGW32CE__ */
+
+#endif
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 windows.h
+
+#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, 

[libav-devel] [PATCH] crypto: Use av_freep instead of av_free

2011-04-24 Thread Martin Storsjö
Using av_freep is generally good practice.
---
 libavformat/crypto.c |6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/libavformat/crypto.c b/libavformat/crypto.c
index ea6012a..fecc2c9 100644
--- a/libavformat/crypto.c
+++ b/libavformat/crypto.c
@@ -153,9 +153,9 @@ 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);
+av_freep(c-aes);
+av_freep(c-key);
+av_freep(c-iv);
 return 0;
 }
 
-- 
1.7.3.1

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH] applehttp: Don't export variant_bitrate if it isn't known

2011-04-24 Thread Martin Storsjö
If there are no variants, the total bitrate of the single
stream isn't known, and exporting variant_bitrate = 0 does
look weird, since there really aren't any variants.
---
 libavformat/applehttp.c |4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/libavformat/applehttp.c b/libavformat/applehttp.c
index 2e0e8a1..822d80b 100644
--- a/libavformat/applehttp.c
+++ b/libavformat/applehttp.c
@@ -505,7 +505,9 @@ static int applehttp_read_header(AVFormatContext *s, 
AVFormatParameters *ap)
 goto fail;
 }
 avcodec_copy_context(st-codec, v-ctx-streams[j]-codec);
-av_metadata_set2(st-metadata, variant_bitrate, bitrate_str, 0);
+if (v-bandwidth)
+av_metadata_set2(st-metadata, variant_bitrate, bitrate_str,
+ 0);
 }
 stream_offset += v-ctx-nb_streams;
 }
-- 
1.7.3.1

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH] win32: include the correct header in cmdutils.c

2011-04-25 Thread Martin Storsjö
On Mon, 25 Apr 2011, lu_z...@gentoo.org wrote:

 From: Luca Barbato lu_z...@gentoo.org
 
 CommandLineToArgvW requires windows.h, include it directly
 ---
  cmdutils.c |1 +
  1 files changed, 1 insertions(+), 0 deletions(-)
 
 diff --git a/cmdutils.c b/cmdutils.c
 index f25f61d..d15aba0 100644
 --- a/cmdutils.c
 +++ b/cmdutils.c
 @@ -156,6 +156,7 @@ static const OptionDef* find_option(const OptionDef *po, 
 const char *name){
  }
  
  #if defined(_WIN32)  !defined(__MINGW32CE__)
 +#include windows.h
  /* Will be leaked on exit */
  static char** win32_argv_utf8 = NULL;
  static int win32_argc = 0;

Ok

// Martin
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH] no infinite wait on remote host disconnect

2011-04-26 Thread Martin Storsjö
On Tue, 26 Apr 2011, Gil Pedersen wrote:

 Attached patch will allow ff_network_wait_fd() to return when the fd 
 encounters an error or disconnection (HUP). Once returned, the next 
 read/write call on the fd will result in an error and possibly a signal, 
 which should provide better feedback than the current method of waiting 
 indefinitely.

 diff --git a/libavformat/network.h b/libavformat/network.h
 index 84a8f53..37ef22e 100644
 --- a/libavformat/network.h
 +++ b/libavformat/network.h
 @@ -78,7 +78,7 @@ static inline int ff_network_wait_fd(int fd, int write)
  struct pollfd p = { .fd = fd, .events = ev, .revents = 0 };
  int ret;
  ret = poll(p, 1, 100);
 -return ret  0 ? ff_neterrno() : p.revents  ev ? 0 : AVERROR(EAGAIN);
 +return ret  0 ? ff_neterrno() : p.revents  (ev | POLLERR | POLLHUP) ? 
 0 : AVERROR(EAGAIN);
  }
  
  static inline void ff_network_close(void)

Looks ok to me.

Further, I thought if we perhaps should return a better error code than 
just 0 for those cases? But on the other hand, when returning 0, the 
caller just proceeds to do the recv()/send(), which will return a proper 
error code anyway. So I guess this is ok.

Btw, to make sure your patch is attributed correctly, git format-patch is 
recommended :-)

// Martin
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH] avio: Fix the deprecated fallback URL-prefixed open flags

2011-04-28 Thread Martin Storsjö
While deprecated, they're totally useless as long as their values
are different from the AVIO_FLAG values that are used internally.
Currently, this leads to old libav applications still compiling
correctly (since we haven't removed the fallback wrappers), but
failing since the functions internally compare to the new AVIO_FLAG
values.

These should be removed at some point, but they aren't removed yet.
The intent is to be able to recompile an old application against
the new ABI without modifying the code, and this doesn't work
currently.
---
 libavformat/avio.h |6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/libavformat/avio.h b/libavformat/avio.h
index a4ab5ae..b98137b 100644
--- a/libavformat/avio.h
+++ b/libavformat/avio.h
@@ -150,9 +150,9 @@ attribute_deprecated int url_poll(URLPollEntry *poll_table, 
int n, int timeout);
  * constants, optionally ORed with other flags.
  * @{
  */
-#define URL_RDONLY 0  /** read-only */
-#define URL_WRONLY 1  /** write-only */
-#define URL_RDWR   2  /** read-write */
+#define URL_RDONLY 1  /** read-only */
+#define URL_WRONLY 2  /** write-only */
+#define URL_RDWR   (URL_RDONLY|URL_WRONLY)  /** read-write */
 /**
  * @}
  */
-- 
1.7.3.1

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH] vorbisdec: Replace some sizeof(type) by sizeof(variable).

2011-04-28 Thread Martin Storsjö
On Thu, 28 Apr 2011, Diego Biurrun wrote:

 ---
  libavcodec/vorbisdec.c |6 +++---
  1 files changed, 3 insertions(+), 3 deletions(-)
 
 diff --git a/libavcodec/vorbisdec.c b/libavcodec/vorbisdec.c
 index a9ddc7d..4bd842e 100644
 --- a/libavcodec/vorbisdec.c
 +++ b/libavcodec/vorbisdec.c
 @@ -735,8 +735,8 @@ static int vorbis_parse_setup_hdr_mappings(vorbis_context 
 *vc)
  
  if (get_bits1(gb)) {
  mapping_setup-coupling_steps = get_bits(gb, 8) + 1;
 -mapping_setup-magnitude  = 
 av_mallocz(mapping_setup-coupling_steps * sizeof(uint_fast8_t));
 -mapping_setup-angle  = 
 av_mallocz(mapping_setup-coupling_steps * sizeof(uint_fast8_t));
 +mapping_setup-magnitude  = 
 av_mallocz(mapping_setup-coupling_steps * sizeof(mapping_setup-magnitude));
 +mapping_setup-angle  = 
 av_mallocz(mapping_setup-coupling_steps * sizeof(mapping_setup-angle));
  for (j = 0; j  mapping_setup-coupling_steps; ++j) {
  GET_VALIDATED_INDEX(mapping_setup-magnitude[j], 
 ilog(vc-audio_channels - 1), vc-audio_channels)
  GET_VALIDATED_INDEX(mapping_setup-angle[j], 
 ilog(vc-audio_channels - 1), vc-audio_channels)
 @@ -753,7 +753,7 @@ static int vorbis_parse_setup_hdr_mappings(vorbis_context 
 *vc)
  }
  
  if (mapping_setup-submaps1) {
 -mapping_setup-mux = av_mallocz(vc-audio_channels * 
 sizeof(uint_fast8_t));
 +mapping_setup-mux = av_mallocz(vc-audio_channels * 
 sizeof(mapping_setup-mux));
  for (j = 0; j  vc-audio_channels; ++j)
  mapping_setup-mux[j] = get_bits(gb, 4);
  }

This isn't right - as Måns pointed out in reply to the earlier mail, you 
should do

ptr = malloc(count * sizeof(*ptr))

Now you do sizeof(ptr), which isn't what you want (usually it might be as 
big or bigger than what you want, in some cases it might be smaller).

// Martin___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH] avio: Fix the deprecated fallback URL-prefixed open flags

2011-04-28 Thread Martin Storsjö
On Thu, 28 Apr 2011, Luca Barbato wrote:

 On 4/28/11 9:41 AM, Martin Storsjö wrote:
  These should be removed at some point, but they aren't removed yet.
  The intent is to be able to recompile an old application against
  the new ABI without modifying the code, and this doesn't work
  currently.
 
 Ok.

Discussed with Anton on irc, and he was ok with it, too. Pushed.

// Martin___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] respecting AVFMT_FLAG_NONBLOCK in AVIO

2011-05-01 Thread Martin Storsjö
On Sun, 1 May 2011, aviad rozenhek wrote:

 On Sun, May 1, 2011 at 16:04, Ronald S. Bultje rsbul...@gmail.com wrote:
  We need a demuxer-supports-nonblock (or doesnotsupport-nonblock) flag
  so we can turn it off for the demuxers not supporting it.
 
 doesn't retry_transfer_wrapper() already take care of this without requiring
 explicit support in demuxers?

No - what retry_transfer_wrapper does is makes a nonblocking protocol 
(that is, one that can return AVERROR(EAGAIN)) blocking, unless the 
nonblocking flag is set.

However, for this to be useful, all demuxers that read data need to be 
ready to handle an AVERROR(EAGAIN) at any point. E.g., imagine a normal 
demuxer reading a packet from a TCP stream. Halfway through the packet, 
the input AVIO returns AVERROR(EAGAIN) - then the demuxer would have to 
store the halfway parsed packet internally, return AVERROR(EAGAIN) to the 
caller, and resume parsing the packet on the next av_read_frame() call. 
(Rewinding the AVIO would be one way of dealing with this a bit simpler, 
but wouldn't work if the start of the packet has been flushed from the 
AVIO buffer.)

If you think of datagram inputs, then you normally don't have the same 
issue - if you get some data, you usually get the full packet. But for 
byte streams, you can't count on this, the EAGAIN returns from the IO 
doesn't correspond to packet boundaries in the container that is streamed 
at all.

Which demuxer and protocol did you want to use it with more concretely, in 
this case?

// Martin___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH] udp: Fix receiving RTP data over multicast

2011-05-09 Thread Martin Storsjö
Earlier, AVIO_RDWR was handled as READ, and all the checks
for the AVIO_WRONLY flag explicitly meant the write-only case.
When changed from old AVIO/URL contants to AVIO_FLAG in
59d96941f0285a5, these comparisons were updated incorrectly, by
mapping checks for AVIO_WRONLY to checks for AVIO_FLAG_WRITE.

When receiving RTP over UDP, the urlcontext is opened with
READ_WRITE flags.

This patch updates the flag comparisons to check for the same
conditions as the code did prior to 59d96941f0285a5.
---
 libavformat/udp.c |   12 ++--
 1 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/libavformat/udp.c b/libavformat/udp.c
index 932eb19..62c1c7c 100644
--- a/libavformat/udp.c
+++ b/libavformat/udp.c
@@ -315,7 +315,7 @@ static int udp_open(URLContext *h, const char *uri, int 
flags)
 h-is_streamed = 1;
 h-max_packet_size = 1472;
 
-is_output = (flags  AVIO_FLAG_WRITE);
+is_output = !(flags  AVIO_FLAG_READ);
 
 s = av_mallocz(sizeof(UDPContext));
 if (!s)
@@ -358,14 +358,14 @@ static int udp_open(URLContext *h, const char *uri, int 
flags)
 /* XXX: fix av_url_split */
 if (hostname[0] == '\0' || hostname[0] == '?') {
 /* only accepts null hostname if input */
-if (flags  AVIO_FLAG_WRITE)
+if (!(flags  AVIO_FLAG_READ))
 goto fail;
 } else {
 if (ff_udp_set_remote_url(h, uri)  0)
 goto fail;
 }
 
-if (s-is_multicast  !(h-flags  AVIO_FLAG_WRITE))
+if (s-is_multicast  (h-flags  AVIO_FLAG_READ))
 s-local_port = port;
 udp_fd = udp_socket_create(s, my_addr, len);
 if (udp_fd  0)
@@ -382,7 +382,7 @@ static int udp_open(URLContext *h, const char *uri, int 
flags)
 
 /* the bind is needed to give a port to the socket now */
 /* if multicast, try the multicast address bind first */
-if (s-is_multicast  !(h-flags  AVIO_FLAG_WRITE)) {
+if (s-is_multicast  (h-flags  AVIO_FLAG_READ)) {
 bind_ret = bind(udp_fd,(struct sockaddr *)s-dest_addr, len);
 }
 /* bind to the local address if not multicast or if the multicast
@@ -395,7 +395,7 @@ static int udp_open(URLContext *h, const char *uri, int 
flags)
 s-local_port = udp_port(my_addr, len);
 
 if (s-is_multicast) {
-if (h-flags  AVIO_FLAG_WRITE) {
+if (!(h-flags  AVIO_FLAG_READ)) {
 /* output */
 if (udp_set_multicast_ttl(udp_fd, s-ttl, (struct sockaddr 
*)s-dest_addr)  0)
 goto fail;
@@ -478,7 +478,7 @@ static int udp_close(URLContext *h)
 {
 UDPContext *s = h-priv_data;
 
-if (s-is_multicast  !(h-flags  AVIO_FLAG_WRITE))
+if (s-is_multicast  (h-flags  AVIO_FLAG_READ))
 udp_leave_multicast_group(s-udp_fd, (struct sockaddr *)s-dest_addr);
 closesocket(s-udp_fd);
 av_free(s);
-- 
1.7.3.1

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH] rtpproto: Remove an unused variable

2011-05-09 Thread Martin Storsjö
---
 libavformat/rtpproto.c |4 +---
 1 files changed, 1 insertions(+), 3 deletions(-)

diff --git a/libavformat/rtpproto.c b/libavformat/rtpproto.c
index e1659ee..1340665 100644
--- a/libavformat/rtpproto.c
+++ b/libavformat/rtpproto.c
@@ -138,15 +138,13 @@ static int rtp_open(URLContext *h, const char *uri, int 
flags)
 {
 RTPContext *s;
 int rtp_port, rtcp_port,
-is_output, ttl, connect,
+ttl, connect,
 local_rtp_port, local_rtcp_port, max_packet_size;
 char hostname[256];
 char buf[1024];
 char path[1024];
 const char *p;
 
-is_output = (flags  AVIO_FLAG_WRITE);
-
 s = av_mallocz(sizeof(RTPContext));
 if (!s)
 return AVERROR(ENOMEM);
-- 
1.7.3.1

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH] mpegtsenc: Clear st-priv_data when freeing it

2011-05-09 Thread Martin Storsjö
If not cleared, the caller might try to free it.
---
 libavformat/mpegtsenc.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
index bf66aa0..55a16f7 100644
--- a/libavformat/mpegtsenc.c
+++ b/libavformat/mpegtsenc.c
@@ -588,7 +588,7 @@ static int mpegts_write_header(AVFormatContext *s)
 av_free(pids);
 for(i = 0;i  s-nb_streams; i++) {
 st = s-streams[i];
-av_free(st-priv_data);
+av_freep(st-priv_data);
 }
 return -1;
 }
-- 
1.7.3.1

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH] rtsp: Only do keepalive using GET_PARAMETER if the server supports it

2011-05-09 Thread Martin Storsjö
This is more like what VLC does. If the server doesn't mention
supporting GET_PARAMETER in response to an OPTIONS request,
VLC doesn't send any keepalive requests at all. After this patch,
libavformat will still send OPTIONS keepalives if GET_PARAMETER
isn't explicitly said to be supported.

Some RTSP cameras don't support GET_PARAMETER, and will
close the connection if this is sent as keepalive request
(but support OPTIONS just fine, but probably don't need any
keepalive at all). Some other cameras don't support using
OPTIONS as keepalive, but require GET_PARAMETER instead.
---

This is an attempt to solve the issue reported at
https://ffmpeg.org/trac/ffmpeg/ticket/129. It still is
pending testing both by the reporter of that issue,
and by Tim Ouellette, to make sure it doesn't break
his streams.

 libavformat/rtsp.c|4 
 libavformat/rtsp.h|5 +
 libavformat/rtspdec.c |4 +++-
 3 files changed, 12 insertions(+), 1 deletions(-)

diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c
index 14111e6..2ebf7e0 100644
--- a/libavformat/rtsp.c
+++ b/libavformat/rtsp.c
@@ -808,6 +808,10 @@ void ff_rtsp_parse_line(RTSPMessageHeader *reply, const 
char *buf,
 p += strspn(p, SPACE_CHARS);
 if (method  !strcmp(method, PLAY))
 rtsp_parse_rtp_info(rt, p);
+} else if (av_stristart(p, Public:, p)  rt) {
+if (strstr(p, GET_PARAMETER) 
+method  !strcmp(method, OPTIONS))
+rt-get_parameter_supported = 1;
 }
 }
 
diff --git a/libavformat/rtsp.h b/libavformat/rtsp.h
index e1f1df9..ff66502 100644
--- a/libavformat/rtsp.h
+++ b/libavformat/rtsp.h
@@ -331,6 +331,11 @@ typedef struct RTSPState {
  * Polling array for udp
  */
 struct pollfd *p;
+
+/**
+ * Whether the server supports the GET_PARAMETER method.
+ */
+int get_parameter_supported;
 } RTSPState;
 
 /**
diff --git a/libavformat/rtspdec.c b/libavformat/rtspdec.c
index 866f313..ccfc4d8 100644
--- a/libavformat/rtspdec.c
+++ b/libavformat/rtspdec.c
@@ -341,7 +341,9 @@ retry:
 
 /* send dummy request to keep TCP connection alive */
 if ((av_gettime() - rt-last_cmd_time) / 100 = rt-timeout / 2) {
-if (rt-server_type != RTSP_SERVER_REAL) {
+if (rt-server_type == RTSP_SERVER_WMS ||
+   (rt-server_type != RTSP_SERVER_REAL 
+rt-get_parameter_supported)) {
 ff_rtsp_send_cmd_async(s, GET_PARAMETER, rt-control_uri, NULL);
 } else {
 ff_rtsp_send_cmd_async(s, OPTIONS, *, NULL);
-- 
1.7.3.1

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH] rtpdec_qdm2: Don't try to parse data packet if no configuration is received

2011-05-12 Thread Martin Storsjö
The later parsing of payload data depends on the configuration
being present. If it hasn't been configured properly yet,
parsing a data packet may lead to a crash.
---
 libavformat/rtpdec_qdm2.c |2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/libavformat/rtpdec_qdm2.c b/libavformat/rtpdec_qdm2.c
index 7f5f077..66dd874 100644
--- a/libavformat/rtpdec_qdm2.c
+++ b/libavformat/rtpdec_qdm2.c
@@ -266,6 +266,8 @@ static int qdm2_parse_packet(AVFormatContext *s, 
PayloadContext *qdm,
  * to the decoder that it is OK to initialize. */
 st-codec-codec_id = CODEC_ID_QDM2;
 }
+if (st-codec-codec_id == CODEC_ID_NONE)
+return AVERROR(EAGAIN);
 
 /* subpackets */
 while (end - p = 4) {
-- 
1.7.3.1

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


  1   2   3   4   5   6   7   8   9   10   >