[libav-commits] ac3: move ac3_downmix() from dsputil to ac3dsp

2012-09-12 Thread Mans Rullgard
Module: libav
Branch: master
Commit: 97cb9236cf3c45eb8a8fba8b88bdde6ece3f496f

Author:Mans Rullgard 
Committer: Mans Rullgard 
Date:  Tue Sep 11 17:55:11 2012 +0100

ac3: move ac3_downmix() from dsputil to ac3dsp

Signed-off-by: Mans Rullgard 

---

 libavcodec/ac3dec.c  |   40 ++
 libavcodec/ac3dec.h  |3 -
 libavcodec/ac3dsp.c  |   26 +
 libavcodec/ac3dsp.h  |3 +
 libavcodec/dsputil.c |4 --
 libavcodec/dsputil.h |1 -
 libavcodec/x86/ac3dsp_init.c |  119 ++
 libavcodec/x86/dsputil_mmx.c |  111 ---
 8 files changed, 154 insertions(+), 153 deletions(-)

diff --git a/libavcodec/ac3dec.c b/libavcodec/ac3dec.c
index daa0702..37426c6 100644
--- a/libavcodec/ac3dec.c
+++ b/libavcodec/ac3dec.c
@@ -621,34 +621,6 @@ static inline void do_imdct(AC3DecodeContext *s, int 
channels)
 }
 
 /**
- * Downmix the output to mono or stereo.
- */
-void ff_ac3_downmix_c(float (*samples)[256], float (*matrix)[2],
-  int out_ch, int in_ch, int len)
-{
-int i, j;
-float v0, v1;
-if (out_ch == 2) {
-for (i = 0; i < len; i++) {
-v0 = v1 = 0.0f;
-for (j = 0; j < in_ch; j++) {
-v0 += samples[j][i] * matrix[j][0];
-v1 += samples[j][i] * matrix[j][1];
-}
-samples[0][i] = v0;
-samples[1][i] = v1;
-}
-} else if (out_ch == 1) {
-for (i = 0; i < len; i++) {
-v0 = 0.0f;
-for (j = 0; j < in_ch; j++)
-v0 += samples[j][i] * matrix[j][0];
-samples[0][i] = v0;
-}
-}
-}
-
-/**
  * Upmix delay samples from stereo to original channel layout.
  */
 static void ac3_upmix_delay(AC3DecodeContext *s)
@@ -1266,19 +1238,19 @@ static int decode_audio_block(AC3DecodeContext *s, int 
blk)
 do_imdct(s, s->channels);
 
 if (downmix_output) {
-s->dsp.ac3_downmix(s->output, s->downmix_coeffs,
-   s->out_channels, s->fbw_channels, 256);
+s->ac3dsp.downmix(s->output, s->downmix_coeffs,
+  s->out_channels, s->fbw_channels, 256);
 }
 } else {
 if (downmix_output) {
-s->dsp.ac3_downmix(s->transform_coeffs + 1, s->downmix_coeffs,
-   s->out_channels, s->fbw_channels, 256);
+s->ac3dsp.downmix(s->transform_coeffs + 1, s->downmix_coeffs,
+  s->out_channels, s->fbw_channels, 256);
 }
 
 if (downmix_output && !s->downmixed) {
 s->downmixed = 1;
-s->dsp.ac3_downmix(s->delay, s->downmix_coeffs, s->out_channels,
-   s->fbw_channels, 128);
+s->ac3dsp.downmix(s->delay, s->downmix_coeffs, s->out_channels,
+  s->fbw_channels, 128);
 }
 
 do_imdct(s, s->out_channels);
diff --git a/libavcodec/ac3dec.h b/libavcodec/ac3dec.h
index 56c6553..a2625a6 100644
--- a/libavcodec/ac3dec.h
+++ b/libavcodec/ac3dec.h
@@ -221,9 +221,6 @@ int ff_eac3_parse_header(AC3DecodeContext *s);
  */
 void ff_eac3_decode_transform_coeffs_aht_ch(AC3DecodeContext *s, int ch);
 
-void ff_ac3_downmix_c(float (*samples)[256], float (*matrix)[2],
-  int out_ch, int in_ch, int len);
-
 /**
  * Apply spectral extension to each channel by copying lower frequency
  * coefficients to higher frequency bins and applying side information to
diff --git a/libavcodec/ac3dsp.c b/libavcodec/ac3dsp.c
index b751aec..41f79b9 100644
--- a/libavcodec/ac3dsp.c
+++ b/libavcodec/ac3dsp.c
@@ -171,6 +171,31 @@ static void ac3_extract_exponents_c(uint8_t *exp, int32_t 
*coef, int nb_coefs)
 }
 }
 
+static void ac3_downmix_c(float (*samples)[256], float (*matrix)[2],
+  int out_ch, int in_ch, int len)
+{
+int i, j;
+float v0, v1;
+if (out_ch == 2) {
+for (i = 0; i < len; i++) {
+v0 = v1 = 0.0f;
+for (j = 0; j < in_ch; j++) {
+v0 += samples[j][i] * matrix[j][0];
+v1 += samples[j][i] * matrix[j][1];
+}
+samples[0][i] = v0;
+samples[1][i] = v1;
+}
+} else if (out_ch == 1) {
+for (i = 0; i < len; i++) {
+v0 = 0.0f;
+for (j = 0; j < in_ch; j++)
+v0 += samples[j][i] * matrix[j][0];
+samples[0][i] = v0;
+}
+}
+}
+
 av_cold void ff_ac3dsp_init(AC3DSPContext *c, int bit_exact)
 {
 c->ac3_exponent_min = ac3_exponent_min_c;
@@ -182,6 +207,7 @@ av_cold void ff_ac3dsp_init(AC3DSPContext *c, int bit_exact)
 c->update_bap_counts = ac3_update_bap_counts_c;
 c->compute_mantissa_size = ac3_compute_mantissa_size_c;
 c->extract_exponents = ac3_extract_exponents_c;
+c->downmix = ac3_downmix_c;
 
 if (ARCH_AR

[libav-commits] lavr/audio_mix_matrix: acknowledge the existence of LFE2.

2012-09-12 Thread Tim Walker
Module: libav
Branch: master
Commit: b901c30da606ade7427fbfb0f9651cc5bfb953a7

Author:Tim Walker 
Committer: Justin Ruggles 
Date:  Wed Sep 12 17:09:33 2012 +0200

lavr/audio_mix_matrix: acknowledge the existence of LFE2.

Signed-off-by: Justin Ruggles 

---

 libavresample/audio_mix_matrix.c |1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/libavresample/audio_mix_matrix.c b/libavresample/audio_mix_matrix.c
index 3fbc4a4..01a9336 100644
--- a/libavresample/audio_mix_matrix.c
+++ b/libavresample/audio_mix_matrix.c
@@ -54,6 +54,7 @@
 #define WIDE_RIGHT 32
 #define SURROUND_DIRECT_LEFT   33
 #define SURROUND_DIRECT_RIGHT  34
+#define LOW_FREQUENCY_235
 
 #define SQRT3_2  1.22474487139158904909  /* sqrt(3/2) */
 

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


[libav-commits] mlp_parser: avoid mapping multiple disctinct TrueHD channels to the same Libav channel .

2012-09-12 Thread Tim Walker
Module: libav
Branch: master
Commit: 3844572887e613d0292d7545c4f2a33e3e207882

Author:Tim Walker 
Committer: Justin Ruggles 
Date:  Wed Sep 12 17:09:32 2012 +0200

mlp_parser: avoid mapping multiple disctinct TrueHD channels to the same Libav 
channel.

Signed-off-by: Justin Ruggles 

---

 libavcodec/mlp_parser.c |4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavcodec/mlp_parser.c b/libavcodec/mlp_parser.c
index 016252c..4c1cf9b 100644
--- a/libavcodec/mlp_parser.c
+++ b/libavcodec/mlp_parser.c
@@ -83,10 +83,10 @@ static const uint64_t thd_layout[13] = {
 AV_CH_BACK_LEFT|AV_CH_BACK_RIGHT,   // LRrs
 AV_CH_BACK_CENTER,  // Cs
 AV_CH_TOP_CENTER,   // Ts
-AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT,   // LRsd
+AV_CH_SURROUND_DIRECT_LEFT|AV_CH_SURROUND_DIRECT_RIGHT, // LRsd
 AV_CH_WIDE_LEFT|AV_CH_WIDE_RIGHT,   // LRw
 AV_CH_TOP_FRONT_CENTER, // Cvh
-AV_CH_LOW_FREQUENCY // LFE2
+AV_CH_LOW_FREQUENCY_2,  // LFE2
 };
 
 static int mlp_samplerate(int in)

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


[libav-commits] lavu/audioconvert: add a second low frequency channel.

2012-09-12 Thread Tim Walker
Module: libav
Branch: master
Commit: 8919fee7d259a4f8feb2aac6941ac21915be7b6e

Author:Tim Walker 
Committer: Justin Ruggles 
Date:  Wed Sep 12 17:09:31 2012 +0200

lavu/audioconvert: add a second low frequency channel.

Can be used by DTS-HD, TrueHD and E-AC-3, among others.

Signed-off-by: Justin Ruggles 

---

 doc/APIchanges   |3 +++
 libavutil/audioconvert.c |1 +
 libavutil/audioconvert.h |1 +
 libavutil/version.h  |2 +-
 4 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index 7e1ffd0..48fe097 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -13,6 +13,9 @@ libavutil: 2011-04-18
 
 API changes, most recent first:
 
+2012-09-12 - xxx - lavu 51.41.0 - audioconvert.h
+  Added AV_CH_LOW_FREQUENCY_2 channel mask value.
+
 2012-09-04 - xxx - lavu 51.40.0 - opt.h
   Reordered the fields in default_val in AVOption, changed which
   default_val field is used for which AVOptionType.
diff --git a/libavutil/audioconvert.c b/libavutil/audioconvert.c
index 09750ff..113b9d7 100644
--- a/libavutil/audioconvert.c
+++ b/libavutil/audioconvert.c
@@ -53,6 +53,7 @@ static const char * const channel_names[] = {
 [32] = "WR",/* wide right */
 [33] = "SDL",   /* surround direct left */
 [34] = "SDR",   /* surround direct right */
+[35] = "LFE2",  /* low frequency 2 */
 };
 
 static const char *get_channel_name(int channel_id)
diff --git a/libavutil/audioconvert.h b/libavutil/audioconvert.h
index 7e79097..73076cb 100644
--- a/libavutil/audioconvert.h
+++ b/libavutil/audioconvert.h
@@ -62,6 +62,7 @@
 #define AV_CH_WIDE_RIGHT 0x0001ULL
 #define AV_CH_SURROUND_DIRECT_LEFT   0x0002ULL
 #define AV_CH_SURROUND_DIRECT_RIGHT  0x0004ULL
+#define AV_CH_LOW_FREQUENCY_20x0008ULL
 
 /** Channel mask value used for AVCodecContext.request_channel_layout
 to indicate that the user requests the channel order of the decoder output
diff --git a/libavutil/version.h b/libavutil/version.h
index 293a65b..6342bae 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -37,7 +37,7 @@
  */
 
 #define LIBAVUTIL_VERSION_MAJOR 51
-#define LIBAVUTIL_VERSION_MINOR 40
+#define LIBAVUTIL_VERSION_MINOR 41
 #define LIBAVUTIL_VERSION_MICRO  0
 
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \

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


[libav-commits] mpegts: check substreams before discarding

2012-09-12 Thread Christian Schmidt
Module: libav
Branch: master
Commit: 07584eaf4a95db3f11d3bc411f9786932829e82b

Author:Christian Schmidt 
Committer: Luca Barbato 
Date:  Thu Sep  6 16:43:24 2012 +0200

mpegts: check substreams before discarding

Allow to extract the AC3 core from TrueHD with the "copy" codec.

Signed-off-by: Luca Barbato 

---

 libavformat/mpegts.c |3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
index 40a983b..a3d5e8e 100644
--- a/libavformat/mpegts.c
+++ b/libavformat/mpegts.c
@@ -784,7 +784,8 @@ static int mpegts_push_data(MpegTSFilter *filter,
 code = pes->header[3] | 0x100;
 av_dlog(pes->stream, "pid=%x pes_code=%#x\n", pes->pid, 
code);
 
-if ((pes->st && pes->st->discard == AVDISCARD_ALL) ||
+if ((pes->st && pes->st->discard == AVDISCARD_ALL &&
+ (!pes->sub_st || pes->sub_st->discard == 
AVDISCARD_ALL)) ||
 code == 0x1be) /* padding_stream */
 goto skip;
 

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


[libav-commits] Add a smooth streaming segmenter muxer

2012-09-12 Thread Martin Storsjö
Module: libav
Branch: master
Commit: 62c9ae11a7f9716848de0c26df855d6b8071eb16

Author:Martin Storsjö 
Committer: Martin Storsjö 
Date:  Mon Mar 19 23:12:54 2012 +0200

Add a smooth streaming segmenter muxer

This muxer splits the output from the ismv muxer into individual
files, in realtime.

The same can also be done by the standalone tool ismindex, but this
muxer is needed for doing it in realtime (especially for live
streams that need extra handling for updating the lookahead fields
in the fragment headers).

Using this muxer, one can deliver live smooth streaming from a
normal static file web server. (Using ismindex, one can deliver
premade smooth streaming files from a static file web server,
or prepare files for serving with IIS.)

Signed-off-by: Martin Storsjö 

---

 Changelog|1 +
 libavformat/Makefile |1 +
 libavformat/allformats.c |1 +
 libavformat/os_support.h |7 +
 libavformat/smoothstreamingenc.c |  621 ++
 libavformat/version.h|2 +-
 6 files changed, 632 insertions(+), 1 deletions(-)

diff --git a/Changelog b/Changelog
index b65d4ba..ad3e211 100644
--- a/Changelog
+++ b/Changelog
@@ -47,6 +47,7 @@ version :
 - Ut Video encoder
 - Microsoft Screen 2 decoder
 - RTP depacketization of JPEG
+- Smooth Streaming live segmenter muxer
 
 
 version 0.8:
diff --git a/libavformat/Makefile b/libavformat/Makefile
index 1cc7ebe..ae168b6 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -292,6 +292,7 @@ OBJS-$(CONFIG_SIFF_DEMUXER)  += siff.o
 OBJS-$(CONFIG_SMACKER_DEMUXER)   += smacker.o
 OBJS-$(CONFIG_SMJPEG_DEMUXER)+= smjpegdec.o smjpeg.o
 OBJS-$(CONFIG_SMJPEG_MUXER)  += smjpegenc.o smjpeg.o
+OBJS-$(CONFIG_SMOOTHSTREAMING_MUXER) += smoothstreamingenc.o
 OBJS-$(CONFIG_SOL_DEMUXER)   += sol.o pcm.o
 OBJS-$(CONFIG_SOX_DEMUXER)   += soxdec.o pcm.o
 OBJS-$(CONFIG_SOX_MUXER) += soxenc.o
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index 40770e5..39daec7 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -207,6 +207,7 @@ void av_register_all(void)
 REGISTER_DEMUXER  (SIFF, siff);
 REGISTER_DEMUXER  (SMACKER, smacker);
 REGISTER_MUXDEMUX (SMJPEG, smjpeg);
+REGISTER_MUXER(SMOOTHSTREAMING, smoothstreaming);
 REGISTER_DEMUXER  (SOL, sol);
 REGISTER_MUXDEMUX (SOX, sox);
 REGISTER_MUXDEMUX (SPDIF, spdif);
diff --git a/libavformat/os_support.h b/libavformat/os_support.h
index 8e2eb83..533b06b 100644
--- a/libavformat/os_support.h
+++ b/libavformat/os_support.h
@@ -38,6 +38,13 @@
 #  define fstat(f,s) _fstati64((f), (s))
 #endif /* defined(__MINGW32__) && !defined(__MINGW32CE__) */
 
+#ifdef _WIN32
+#include 
+#define mkdir(a, b) _mkdir(a)
+#else
+#include 
+#endif
+
 static inline int is_dos_path(const char *path)
 {
 #if HAVE_DOS_PATHS
diff --git a/libavformat/smoothstreamingenc.c b/libavformat/smoothstreamingenc.c
new file mode 100644
index 000..5ddba7e
--- /dev/null
+++ b/libavformat/smoothstreamingenc.c
@@ -0,0 +1,621 @@
+/*
+ * Live smooth streaming fragmenter
+ * Copyright (c) 2012 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 "config.h"
+#include 
+#if HAVE_UNISTD_H
+#include 
+#endif
+
+#include "avformat.h"
+#include "internal.h"
+#include "os_support.h"
+#include "avc.h"
+#include "url.h"
+
+#include "libavutil/opt.h"
+#include "libavutil/avstring.h"
+#include "libavutil/mathematics.h"
+#include "libavutil/intreadwrite.h"
+
+typedef struct {
+char file[1024];
+char infofile[1024];
+int64_t start_time, duration;
+int n;
+int64_t start_pos, size;
+} Fragment;
+
+typedef struct {
+AVFormatContext *ctx;
+int ctx_inited;
+char dirname[1024];
+uint8_t iobuf[32768];
+URLContext *out;  // Current output stream where all output is written
+URLContext *out2; // Auxillary output stream where all output also is 
written
+URLContext *tail_out; // The actual main output stream, if we're currently 
seeked back to write elsewhere
+int64_t tail_pos, cur_pos, cur_start_pos;
+int packets_written;
+const char *stream_type_tag;

[libav-commits] file: Add an avoption for disabling truncating existing files on open

2012-09-12 Thread Martin Storsjö
Module: libav
Branch: master
Commit: 29a9b12b10c91c638205da74f3330acd06517ae8

Author:Martin Storsjö 
Committer: Martin Storsjö 
Date:  Sun Sep  9 22:42:56 2012 +0300

file: Add an avoption for disabling truncating existing files on open

Signed-off-by: Martin Storsjö 

---

 libavformat/file.c |   24 ++--
 1 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/libavformat/file.c b/libavformat/file.c
index 3cfd28c..3ea681f 100644
--- a/libavformat/file.c
+++ b/libavformat/file.c
@@ -20,6 +20,7 @@
  */
 
 #include "libavutil/avstring.h"
+#include "libavutil/opt.h"
 #include "avformat.h"
 #include 
 #if HAVE_IO_H
@@ -37,9 +38,23 @@
 /* standard file protocol */
 
 typedef struct FileContext {
+const AVClass *class;
 int fd;
+int trunc;
 } FileContext;
 
+static const AVOption file_options[] = {
+{ "truncate", "Truncate existing files on write", offsetof(FileContext, 
trunc), AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 1, AV_OPT_FLAG_ENCODING_PARAM },
+{ NULL }
+};
+
+static const AVClass file_class = {
+.class_name = "file",
+.item_name  = av_default_item_name,
+.option = file_options,
+.version= LIBAVUTIL_VERSION_INT,
+};
+
 static int file_read(URLContext *h, unsigned char *buf, int size)
 {
 FileContext *c = h->priv_data;
@@ -82,9 +97,13 @@ static int file_open(URLContext *h, const char *filename, 
int flags)
 av_strstart(filename, "file:", &filename);
 
 if (flags & AVIO_FLAG_WRITE && flags & AVIO_FLAG_READ) {
-access = O_CREAT | O_TRUNC | O_RDWR;
+access = O_CREAT | O_RDWR;
+if (c->trunc)
+access |= O_TRUNC;
 } else if (flags & AVIO_FLAG_WRITE) {
-access = O_CREAT | O_TRUNC | O_WRONLY;
+access = O_CREAT | O_WRONLY;
+if (c->trunc)
+access |= O_TRUNC;
 } else {
 access = O_RDONLY;
 }
@@ -126,6 +145,7 @@ URLProtocol ff_file_protocol = {
 .url_get_file_handle = file_get_handle,
 .url_check   = file_check,
 .priv_data_size  = sizeof(FileContext),
+.priv_data_class = &file_class,
 };
 
 #endif /* CONFIG_FILE_PROTOCOL */

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

[libav-commits] download: clearly split the git repositories table

2012-09-12 Thread Luca Barbato
Module: libav.org
Branch: master
Commit: 7edb0e6c0df5f35a75f909942cc42d6b4aef77d2

Author:Luca Barbato 
Committer: Luca Barbato 
Date:  Wed Sep 12 12:48:17 2012 +0200

download: clearly split the git repositories table

Add thead and tbody where needed.

---

 src/download |8 
 1 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/src/download b/src/download
index 7ac5cb6..acc92fa 100644
--- a/src/download
+++ b/src/download
@@ -46,9 +46,13 @@ developers and groups of developers are available.
 Libav team
 Website module
 
+
+
 
  Mirrors 
 
+
+
 
 git://gitorious.org/libav/libav.git
 http://gitorious.org/libav/libav";>http://gitorious.org/libav/libav
@@ -66,9 +70,13 @@ developers and groups of developers are available.
 Libav team
 Github Mirror
 
+
+
 
  Developer Trees 
 
+
+
 
 git://gitorious.org/~astrange/ffmpeg/ffmpeg-mt.git
 http://gitorious.org/~astrange/ffmpeg/ffmpeg-mt";>http://gitorious.org/~astrange/ffmpeg/ffmpeg-mt

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


[libav-commits] img2dec: always close AVIOContexts

2012-09-12 Thread Tomas Härdin
Module: libav
Branch: master
Commit: 5e3572893d7f17679c5e051c511bf42f3da77b00

Author:Tomas Härdin 
Committer: Luca Barbato 
Date:  Fri Sep  7 13:28:48 2012 +0200

img2dec: always close AVIOContexts

Zero sized files would cause the contexts to leak away.

Signed-off-by: Luca Barbato 

---

 libavformat/img2dec.c |6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/libavformat/img2dec.c b/libavformat/img2dec.c
index 2f5092f..1151180 100644
--- a/libavformat/img2dec.c
+++ b/libavformat/img2dec.c
@@ -216,7 +216,7 @@ static int read_packet(AVFormatContext *s1, AVPacket *pkt)
 char filename[1024];
 int i;
 int size[3]={0}, ret[3]={0};
-AVIOContext *f[3];
+AVIOContext *f[3] = {NULL};
 AVCodecContext *codec= s1->streams[0]->codec;
 
 if (!s->is_pipe) {
@@ -232,7 +232,7 @@ static int read_packet(AVFormatContext *s1, AVPacket *pkt)
 for(i=0; i<3; i++){
 if (avio_open2(&f[i], filename, AVIO_FLAG_READ,
&s1->interrupt_callback, NULL) < 0) {
-if(i==1)
+if(i>=1)
 break;
 av_log(s1, AV_LOG_ERROR, "Could not open file : 
%s\n",filename);
 return AVERROR(EIO);
@@ -259,7 +259,7 @@ static int read_packet(AVFormatContext *s1, AVPacket *pkt)
 
 pkt->size= 0;
 for(i=0; i<3; i++){
-if(size[i]){
+if(f[i]){
 ret[i]= avio_read(f[i], pkt->data + pkt->size, size[i]);
 if (!s->is_pipe)
 avio_close(f[i]);

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

[libav-commits] rtpdec_jpeg: Store and reuse old qtables for q values 128-254

2012-09-12 Thread Martin Storsjö
Module: libav
Branch: master
Commit: a218deb856e7352b16e5aa3013a2b3fcdd0e3d2f

Author:Martin Storsjö 
Committer: Martin Storsjö 
Date:  Tue Sep 11 14:29:54 2012 +0300

rtpdec_jpeg: Store and reuse old qtables for q values 128-254

Signed-off-by: Martin Storsjö 

---

 libavformat/rtpdec_jpeg.c |   33 +++--
 1 files changed, 27 insertions(+), 6 deletions(-)

diff --git a/libavformat/rtpdec_jpeg.c b/libavformat/rtpdec_jpeg.c
index 463bf43..9dd5f68 100644
--- a/libavformat/rtpdec_jpeg.c
+++ b/libavformat/rtpdec_jpeg.c
@@ -32,6 +32,8 @@ struct PayloadContext {
 AVIOContext *frame; ///< current frame buffer
 uint32_ttimestamp;  ///< current frame timestamp
 int hdr_size;   ///< size of the current frame header
+uint8_t qtables[128][128];
+uint8_t qtables_len[128];
 };
 
 static const uint8_t default_quantizers[128] = {
@@ -267,12 +269,6 @@ static int jpeg_parse_packet(AVFormatContext *ctx, 
PayloadContext *jpeg,
 if (precision)
 av_log(ctx, AV_LOG_WARNING, "Only 8-bit precision is 
supported.\n");
 
-if (q == 255 && qtable_len == 0) {
-av_log(ctx, AV_LOG_ERROR,
-   "Invalid RTP/JPEG packet. Quantization tables not 
found.\n");
-return AVERROR_INVALIDDATA;
-}
-
 if (qtable_len > 0) {
 if (len < qtable_len) {
 av_log(ctx, AV_LOG_ERROR, "Too short RTP/JPEG packet.\n");
@@ -281,6 +277,31 @@ static int jpeg_parse_packet(AVFormatContext *ctx, 
PayloadContext *jpeg,
 qtables = buf;
 buf += qtable_len;
 len -= qtable_len;
+if (q < 255) {
+if (jpeg->qtables_len[q - 128] &&
+(jpeg->qtables_len[q - 128] != qtable_len ||
+ memcmp(qtables, &jpeg->qtables[q - 128][0], 
qtable_len))) {
+av_log(ctx, AV_LOG_WARNING,
+   "Quantization tables for q=%d changed\n", q);
+} else if (!jpeg->qtables_len[q - 128] && qtable_len <= 
128) {
+memcpy(&jpeg->qtables[q - 128][0], qtables,
+   qtable_len);
+jpeg->qtables_len[q - 128] = qtable_len;
+}
+}
+} else {
+if (q == 255) {
+av_log(ctx, AV_LOG_ERROR,
+   "Invalid RTP/JPEG packet. Quantization tables not 
found.\n");
+return AVERROR_INVALIDDATA;
+}
+if (!jpeg->qtables_len[q - 128]) {
+av_log(ctx, AV_LOG_ERROR,
+   "No quantization tables known for q=%d yet.\n", q);
+return AVERROR_INVALIDDATA;
+}
+qtables= &jpeg->qtables[q - 128][0];
+qtable_len =  jpeg->qtables_len[q - 128];
 }
 }
 

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

[libav-commits] rtpdec_jpeg: Fold the default qtables case into an existing if statement

2012-09-12 Thread Martin Storsjö
Module: libav
Branch: master
Commit: 1de9317bd08d71b6b988a8a64de18f4c2f98e031

Author:Martin Storsjö 
Committer: Martin Storsjö 
Date:  Tue Sep 11 14:39:58 2012 +0300

rtpdec_jpeg: Fold the default qtables case into an existing if statement

Signed-off-by: Martin Storsjö 

---

 libavformat/rtpdec_jpeg.c |   10 --
 1 files changed, 4 insertions(+), 6 deletions(-)

diff --git a/libavformat/rtpdec_jpeg.c b/libavformat/rtpdec_jpeg.c
index 9dd5f68..3f47e71 100644
--- a/libavformat/rtpdec_jpeg.c
+++ b/libavformat/rtpdec_jpeg.c
@@ -303,6 +303,10 @@ static int jpeg_parse_packet(AVFormatContext *ctx, 
PayloadContext *jpeg,
 qtables= &jpeg->qtables[q - 128][0];
 qtable_len =  jpeg->qtables_len[q - 128];
 }
+} else { /* q <= 127 */
+create_default_qtables(new_qtables, q);
+qtables= new_qtables;
+qtable_len = sizeof(new_qtables);
 }
 
 /* Skip the current frame in case of the end packet
@@ -313,12 +317,6 @@ static int jpeg_parse_packet(AVFormatContext *ctx, 
PayloadContext *jpeg,
 return ret;
 jpeg->timestamp = *timestamp;
 
-if (!qtables) {
-create_default_qtables(new_qtables, q);
-qtables= new_qtables;
-qtable_len = sizeof(new_qtables);
-}
-
 /* Generate a frame and scan headers that can be prepended to the
  * RTP/JPEG data payload to produce a JPEG compressed image in
  * interchange format. */

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

[libav-commits] rtpdec_jpeg: Simplify the calculation of the number of qtables

2012-09-12 Thread Martin Storsjö
Module: libav
Branch: master
Commit: a252649059b7dd1fa05e27bd6a14b5a08436456a

Author:Martin Storsjö 
Committer: Martin Storsjö 
Date:  Tue Sep 11 14:43:10 2012 +0300

rtpdec_jpeg: Simplify the calculation of the number of qtables

Signed-off-by: Martin Storsjö 

---

 libavformat/rtpdec_jpeg.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/libavformat/rtpdec_jpeg.c b/libavformat/rtpdec_jpeg.c
index b1361cd..463bf43 100644
--- a/libavformat/rtpdec_jpeg.c
+++ b/libavformat/rtpdec_jpeg.c
@@ -303,7 +303,7 @@ static int jpeg_parse_packet(AVFormatContext *ctx, 
PayloadContext *jpeg,
  * interchange format. */
 jpeg->hdr_size = jpeg_create_header(hdr, sizeof(hdr), type, width,
 height, qtables,
-qtable_len > 64 ? 2 : 1);
+qtable_len / 64);
 
 /* Copy JPEG header to frame buffer. */
 avio_write(jpeg->frame, hdr, jpeg->hdr_size);

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

[libav-commits] rtpdec_jpeg: Disallow using the reserved q values

2012-09-12 Thread Martin Storsjö
Module: libav
Branch: master
Commit: 1743938df10dd888484f964d5af8fd3957d26809

Author:Martin Storsjö 
Committer: Martin Storsjö 
Date:  Tue Sep 11 14:41:42 2012 +0300

rtpdec_jpeg: Disallow using the reserved q values

Signed-off-by: Martin Storsjö 

---

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

diff --git a/libavformat/rtpdec_jpeg.c b/libavformat/rtpdec_jpeg.c
index 3f47e71..3f53887 100644
--- a/libavformat/rtpdec_jpeg.c
+++ b/libavformat/rtpdec_jpeg.c
@@ -304,6 +304,10 @@ static int jpeg_parse_packet(AVFormatContext *ctx, 
PayloadContext *jpeg,
 qtable_len =  jpeg->qtables_len[q - 128];
 }
 } else { /* q <= 127 */
+if (q == 0 || q > 99) {
+av_log(ctx, AV_LOG_ERROR, "Reserved q value %d\n", q);
+return AVERROR_INVALIDDATA;
+}
 create_default_qtables(new_qtables, q);
 qtables= new_qtables;
 qtable_len = sizeof(new_qtables);

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

[libav-commits] rtpdec_jpeg: Error out on other unsupported type values as well

2012-09-12 Thread Martin Storsjö
Module: libav
Branch: master
Commit: c3bcd22ed3f843f7240fa190df8f3daa2081290f

Author:Martin Storsjö 
Committer: Martin Storsjö 
Date:  Tue Sep 11 14:42:22 2012 +0300

rtpdec_jpeg: Error out on other unsupported type values as well

Signed-off-by: Martin Storsjö 

---

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

diff --git a/libavformat/rtpdec_jpeg.c b/libavformat/rtpdec_jpeg.c
index 3f53887..944758d 100644
--- a/libavformat/rtpdec_jpeg.c
+++ b/libavformat/rtpdec_jpeg.c
@@ -246,6 +246,10 @@ static int jpeg_parse_packet(AVFormatContext *ctx, 
PayloadContext *jpeg,
"Unimplemented RTP/JPEG restart marker header.\n");
 return AVERROR_PATCHWELCOME;
 }
+if (type > 1) {
+av_log(ctx, AV_LOG_ERROR, "Unimplemented RTP/JPEG type %d\n", type);
+return AVERROR_PATCHWELCOME;
+}
 
 /* Parse the quantization table header. */
 if (off == 0) {

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

[libav-commits] rtpdec_jpeg: Don't needlessly use a bitstream writer for the header

2012-09-12 Thread Martin Storsjö
Module: libav
Branch: master
Commit: 20f325f320c6e18ee88983870d2a1fee94257293

Author:Martin Storsjö 
Committer: Martin Storsjö 
Date:  Tue Sep 11 12:44:25 2012 +0300

rtpdec_jpeg: Don't needlessly use a bitstream writer for the header

Everything written with this bitstream writer is 8/16 bit units
(except for a pair of 4 bit values), so using a bitstream writer
isn't necessary.

Signed-off-by: Martin Storsjö 

---

 libavformat/rtpdec_jpeg.c |  114 +++--
 1 files changed, 58 insertions(+), 56 deletions(-)

diff --git a/libavformat/rtpdec_jpeg.c b/libavformat/rtpdec_jpeg.c
index 1c75c47..4f52c31b 100644
--- a/libavformat/rtpdec_jpeg.c
+++ b/libavformat/rtpdec_jpeg.c
@@ -23,6 +23,7 @@
 #include "rtpdec_formats.h"
 #include "libavutil/intreadwrite.h"
 #include "libavcodec/mjpeg.h"
+#include "libavcodec/bytestream.h"
 
 /**
  * RTP/JPEG specific private data.
@@ -76,71 +77,75 @@ static void jpeg_free_context(PayloadContext *jpeg)
 av_free(jpeg);
 }
 
-static int jpeg_create_huffman_table(PutBitContext *p, int table_class,
+static int jpeg_create_huffman_table(PutByteContext *p, int table_class,
  int table_id, const uint8_t *bits_table,
  const uint8_t *value_table)
 {
 int i, n = 0;
 
-put_bits(p, 4, table_class);
-put_bits(p, 4, table_id);
+bytestream2_put_byte(p, table_class << 4 | table_id);
 
 for (i = 1; i <= 16; i++) {
 n += bits_table[i];
-put_bits(p, 8, bits_table[i]);
+bytestream2_put_byte(p, bits_table[i]);
 }
 
 for (i = 0; i < n; i++) {
-put_bits(p, 8, value_table[i]);
+bytestream2_put_byte(p, value_table[i]);
 }
 return n + 17;
 }
 
+static void jpeg_put_marker(PutByteContext *pbc, int code)
+{
+bytestream2_put_byte(pbc, 0xff);
+bytestream2_put_byte(pbc, code);
+}
+
 static int jpeg_create_header(uint8_t *buf, int size, uint32_t type, uint32_t 
w,
   uint32_t h, const uint8_t *qtable, int nb_qtable)
 {
-PutBitContext pbc;
+PutByteContext pbc;
 uint8_t *dht_size_ptr;
 int dht_size, i;
 
-init_put_bits(&pbc, buf, size);
+bytestream2_init_writer(&pbc, buf, size);
 
 /* Convert from blocks to pixels. */
 w <<= 3;
 h <<= 3;
 
 /* SOI */
-put_marker(&pbc, SOI);
+jpeg_put_marker(&pbc, SOI);
 
 /* JFIF header */
-put_marker(&pbc, APP0);
-put_bits(&pbc, 16, 16);
-avpriv_put_string(&pbc, "JFIF", 1);
-put_bits(&pbc, 16, 0x0201);
-put_bits(&pbc, 8, 0);
-put_bits(&pbc, 16, 1);
-put_bits(&pbc, 16, 1);
-put_bits(&pbc, 8, 0);
-put_bits(&pbc, 8, 0);
+jpeg_put_marker(&pbc, APP0);
+bytestream2_put_be16(&pbc, 16);
+bytestream2_put_buffer(&pbc, "JFIF", 5);
+bytestream2_put_be16(&pbc, 0x0201);
+bytestream2_put_byte(&pbc, 0);
+bytestream2_put_be16(&pbc, 1);
+bytestream2_put_be16(&pbc, 1);
+bytestream2_put_byte(&pbc, 0);
+bytestream2_put_byte(&pbc, 0);
 
 /* DQT */
-put_marker(&pbc, DQT);
-put_bits(&pbc, 16, 2 + nb_qtable * (1 + 64));
+jpeg_put_marker(&pbc, DQT);
+bytestream2_put_be16(&pbc, 2 + nb_qtable * (1 + 64));
 
 for (i = 0; i < nb_qtable; i++) {
-put_bits(&pbc, 8, i);
+bytestream2_put_byte(&pbc, i);
 
 /* Each table is an array of 64 values given in zig-zag
  * order, identical to the format used in a JFIF DQT
  * marker segment. */
-avpriv_copy_bits(&pbc, qtable + 64 * i, 64 * 8);
+bytestream2_put_buffer(&pbc, qtable + 64 * i, 64);
 }
 
 /* DHT */
-put_marker(&pbc, DHT);
-flush_put_bits(&pbc);
-dht_size_ptr = put_bits_ptr(&pbc);
-put_bits(&pbc, 16, 0);
+jpeg_put_marker(&pbc, DHT);
+dht_size_ptr = pbc.buffer;
+bytestream2_put_be16(&pbc, 0);
 
 dht_size  = 2;
 dht_size += jpeg_create_huffman_table(&pbc, 0, 
0,avpriv_mjpeg_bits_dc_luminance,
@@ -154,41 +159,38 @@ static int jpeg_create_header(uint8_t *buf, int size, 
uint32_t type, uint32_t w,
 AV_WB16(dht_size_ptr, dht_size);
 
 /* SOF0 */
-put_marker(&pbc, SOF0);
-put_bits(&pbc, 16, 17);
-put_bits(&pbc, 8, 8);
-put_bits(&pbc, 16, h);
-put_bits(&pbc, 16, w);
-put_bits(&pbc, 8, 3);
-put_bits(&pbc, 8, 1);
-put_bits(&pbc, 8, type ? 34 : 33);
-put_bits(&pbc, 8, 0);
-put_bits(&pbc, 8, 2);
-put_bits(&pbc, 8, 17);
-put_bits(&pbc, 8, nb_qtable == 2 ? 1 : 0);
-put_bits(&pbc, 8, 3);
-put_bits(&pbc, 8, 17);
-put_bits(&pbc, 8, nb_qtable == 2 ? 1 : 0);
+jpeg_put_marker(&pbc, SOF0);
+bytestream2_put_be16(&pbc, 17);
+bytestream2_put_byte(&pbc, 8);
+bytestream2_put_be16(&pbc, h);
+bytestream2_put_be16(&pbc, w);
+bytestream2_put_byte(&pbc, 3);
+bytestream2_put_byte(&pbc, 1);
+bytestream2_put_byte(&pbc, type ? 34 : 33);
+bytestream2_put_byte(&pbc, 0);
+bytestream2_put_byte(&pbc, 2);
+bytestream

[libav-commits] rtpdec_jpeg: Add more comments about the fields in the SOF0 section

2012-09-12 Thread Martin Storsjö
Module: libav
Branch: master
Commit: cbaa9eeda3c2ca8532b8bf69c9979f30284414ff

Author:Martin Storsjö 
Committer: Martin Storsjö 
Date:  Tue Sep 11 12:54:06 2012 +0300

rtpdec_jpeg: Add more comments about the fields in the SOF0 section

Signed-off-by: Martin Storsjö 

---

 libavformat/rtpdec_jpeg.c |   18 +-
 1 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/libavformat/rtpdec_jpeg.c b/libavformat/rtpdec_jpeg.c
index 20bb356..b1361cd 100644
--- a/libavformat/rtpdec_jpeg.c
+++ b/libavformat/rtpdec_jpeg.c
@@ -160,20 +160,20 @@ static int jpeg_create_header(uint8_t *buf, int size, 
uint32_t type, uint32_t w,
 
 /* SOF0 */
 jpeg_put_marker(&pbc, SOF0);
-bytestream2_put_be16(&pbc, 17);
-bytestream2_put_byte(&pbc, 8);
+bytestream2_put_be16(&pbc, 17); /* size */
+bytestream2_put_byte(&pbc, 8); /* bits per component */
 bytestream2_put_be16(&pbc, h);
 bytestream2_put_be16(&pbc, w);
-bytestream2_put_byte(&pbc, 3);
-bytestream2_put_byte(&pbc, 1);
+bytestream2_put_byte(&pbc, 3); /* number of components */
+bytestream2_put_byte(&pbc, 1); /* component number */
 bytestream2_put_byte(&pbc, (2 << 4) | (type ? 2 : 1)); /* hsample/vsample 
*/
-bytestream2_put_byte(&pbc, 0);
-bytestream2_put_byte(&pbc, 2);
+bytestream2_put_byte(&pbc, 0); /* matrix number */
+bytestream2_put_byte(&pbc, 2); /* component number */
 bytestream2_put_byte(&pbc, 1 << 4 | 1); /* hsample/vsample */
-bytestream2_put_byte(&pbc, nb_qtable == 2 ? 1 : 0);
-bytestream2_put_byte(&pbc, 3);
+bytestream2_put_byte(&pbc, nb_qtable == 2 ? 1 : 0); /* matrix number */
+bytestream2_put_byte(&pbc, 3); /* component number */
 bytestream2_put_byte(&pbc, 1 << 4 | 1); /* hsample/vsample */
-bytestream2_put_byte(&pbc, nb_qtable == 2 ? 1 : 0);
+bytestream2_put_byte(&pbc, nb_qtable == 2 ? 1 : 0); /* matrix number */
 
 /* SOS */
 jpeg_put_marker(&pbc, SOS);

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

[libav-commits] rtpdec_jpeg: Clarify where the subsampling magic numbers come from

2012-09-12 Thread Martin Storsjö
Module: libav
Branch: master
Commit: 31adff08a14b7cd3f4097a4f912108cd64472069

Author:Martin Storsjö 
Committer: Martin Storsjö 
Date:  Tue Sep 11 12:52:55 2012 +0300

rtpdec_jpeg: Clarify where the subsampling magic numbers come from

Write out the numbers the way they are constructed, not just the
final values.

Signed-off-by: Martin Storsjö 

---

 libavformat/rtpdec_jpeg.c |6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/libavformat/rtpdec_jpeg.c b/libavformat/rtpdec_jpeg.c
index 4d8523d..20bb356 100644
--- a/libavformat/rtpdec_jpeg.c
+++ b/libavformat/rtpdec_jpeg.c
@@ -166,13 +166,13 @@ static int jpeg_create_header(uint8_t *buf, int size, 
uint32_t type, uint32_t w,
 bytestream2_put_be16(&pbc, w);
 bytestream2_put_byte(&pbc, 3);
 bytestream2_put_byte(&pbc, 1);
-bytestream2_put_byte(&pbc, type ? 34 : 33);
+bytestream2_put_byte(&pbc, (2 << 4) | (type ? 2 : 1)); /* hsample/vsample 
*/
 bytestream2_put_byte(&pbc, 0);
 bytestream2_put_byte(&pbc, 2);
-bytestream2_put_byte(&pbc, 17);
+bytestream2_put_byte(&pbc, 1 << 4 | 1); /* hsample/vsample */
 bytestream2_put_byte(&pbc, nb_qtable == 2 ? 1 : 0);
 bytestream2_put_byte(&pbc, 3);
-bytestream2_put_byte(&pbc, 17);
+bytestream2_put_byte(&pbc, 1 << 4 | 1); /* hsample/vsample */
 bytestream2_put_byte(&pbc, nb_qtable == 2 ? 1 : 0);
 
 /* SOS */

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

[libav-commits] rtpdec_jpeg: Don't use a bitstream writer for the EOI marker

2012-09-12 Thread Martin Storsjö
Module: libav
Branch: master
Commit: c64d2a63df5d7cd309c184bd0bd33dd2cb1259b1

Author:Martin Storsjö 
Committer: Martin Storsjö 
Date:  Tue Sep 11 12:46:44 2012 +0300

rtpdec_jpeg: Don't use a bitstream writer for the EOI marker

Signed-off-by: Martin Storsjö 

---

 libavformat/rtpdec_jpeg.c |6 +-
 1 files changed, 1 insertions(+), 5 deletions(-)

diff --git a/libavformat/rtpdec_jpeg.c b/libavformat/rtpdec_jpeg.c
index 4f52c31b..4d8523d 100644
--- a/libavformat/rtpdec_jpeg.c
+++ b/libavformat/rtpdec_jpeg.c
@@ -334,13 +334,9 @@ static int jpeg_parse_packet(AVFormatContext *ctx, 
PayloadContext *jpeg,
 
 if (flags & RTP_FLAG_MARKER) {
 /* End of JPEG data packet. */
-PutBitContext pbc;
-uint8_t buf[2];
+uint8_t buf[2] = { 0xff, EOI };
 
 /* Put EOI marker. */
-init_put_bits(&pbc, buf, sizeof(buf));
-put_marker(&pbc, EOI);
-flush_put_bits(&pbc);
 avio_write(jpeg->frame, buf, sizeof(buf));
 
 /* Prepare the JPEG packet. */

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

[libav-commits] rtpdec_jpeg: Simplify writing of the jpeg header

2012-09-12 Thread Martin Storsjö
Module: libav
Branch: master
Commit: 43957fcc71c08697eea7c684900ac793c87e487c

Author:Martin Storsjö 
Committer: Martin Storsjö 
Date:  Tue Sep 11 12:32:37 2012 +0300

rtpdec_jpeg: Simplify writing of the jpeg header

Generalize writing of any number of qtables. Don't manually write
16 bit values in two separate calls.

Signed-off-by: Martin Storsjö 

---

 libavformat/rtpdec_jpeg.c |   28 ++--
 1 files changed, 10 insertions(+), 18 deletions(-)

diff --git a/libavformat/rtpdec_jpeg.c b/libavformat/rtpdec_jpeg.c
index 0513b09..1c75c47 100644
--- a/libavformat/rtpdec_jpeg.c
+++ b/libavformat/rtpdec_jpeg.c
@@ -101,7 +101,7 @@ static int jpeg_create_header(uint8_t *buf, int size, 
uint32_t type, uint32_t w,
 {
 PutBitContext pbc;
 uint8_t *dht_size_ptr;
-int dht_size;
+int dht_size, i;
 
 init_put_bits(&pbc, buf, size);
 
@@ -125,21 +125,15 @@ static int jpeg_create_header(uint8_t *buf, int size, 
uint32_t type, uint32_t w,
 
 /* DQT */
 put_marker(&pbc, DQT);
-if (nb_qtable == 2) {
-put_bits(&pbc, 16, 2 + 2 * (1 + 64));
-} else {
-put_bits(&pbc, 16, 2 + 1 * (1 + 64));
-}
-put_bits(&pbc, 8, 0);
+put_bits(&pbc, 16, 2 + nb_qtable * (1 + 64));
 
-/* Each table is an array of 64 values given in zig-zag
- * order, identical to the format used in a JFIF DQT
- * marker segment. */
-avpriv_copy_bits(&pbc, qtable, 64 * 8);
+for (i = 0; i < nb_qtable; i++) {
+put_bits(&pbc, 8, i);
 
-if (nb_qtable == 2) {
-put_bits(&pbc, 8, 1);
-avpriv_copy_bits(&pbc, qtable + 64, 64 * 8);
+/* Each table is an array of 64 values given in zig-zag
+ * order, identical to the format used in a JFIF DQT
+ * marker segment. */
+avpriv_copy_bits(&pbc, qtable + 64 * i, 64 * 8);
 }
 
 /* DHT */
@@ -163,10 +157,8 @@ static int jpeg_create_header(uint8_t *buf, int size, 
uint32_t type, uint32_t w,
 put_marker(&pbc, SOF0);
 put_bits(&pbc, 16, 17);
 put_bits(&pbc, 8, 8);
-put_bits(&pbc, 8, h >> 8);
-put_bits(&pbc, 8, h);
-put_bits(&pbc, 8, w >> 8);
-put_bits(&pbc, 8, w);
+put_bits(&pbc, 16, h);
+put_bits(&pbc, 16, w);
 put_bits(&pbc, 8, 3);
 put_bits(&pbc, 8, 1);
 put_bits(&pbc, 8, type ? 34 : 33);

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

[libav-commits] rtpdec_jpeg: Merge two if statements

2012-09-12 Thread Martin Storsjö
Module: libav
Branch: master
Commit: 932d8300d38587ebc223e3bacc3c33ed68bf3cf6

Author:Martin Storsjö 
Committer: Martin Storsjö 
Date:  Tue Sep 11 12:07:56 2012 +0300

rtpdec_jpeg: Merge two if statements

This makes the code more readable and robust.

Signed-off-by: Martin Storsjö 

---

 libavformat/rtpdec_jpeg.c |   61 ++---
 1 files changed, 30 insertions(+), 31 deletions(-)

diff --git a/libavformat/rtpdec_jpeg.c b/libavformat/rtpdec_jpeg.c
index 19ecbf4..0513b09 100644
--- a/libavformat/rtpdec_jpeg.c
+++ b/libavformat/rtpdec_jpeg.c
@@ -252,44 +252,43 @@ static int jpeg_parse_packet(AVFormatContext *ctx, 
PayloadContext *jpeg,
 }
 
 /* Parse the quantization table header. */
-if (q > 127 && off == 0) {
-uint8_t precision;
-
-if (len < 4) {
-av_log(ctx, AV_LOG_ERROR, "Too short RTP/JPEG packet.\n");
-return AVERROR_INVALIDDATA;
-}
+if (off == 0) {
+/* Start of JPEG data packet. */
+uint8_t new_qtables[128];
+uint8_t hdr[1024];
 
-/* The first byte is reserved for future use. */
-precision  = AV_RB8(buf + 1);/* size of coefficients */
-qtable_len = AV_RB16(buf + 2);   /* length in bytes */
-buf += 4;
-len -= 4;
+if (q > 127) {
+uint8_t precision;
+if (len < 4) {
+av_log(ctx, AV_LOG_ERROR, "Too short RTP/JPEG packet.\n");
+return AVERROR_INVALIDDATA;
+}
 
-if (precision)
-av_log(ctx, AV_LOG_WARNING, "Only 8-bit precision is 
supported.\n");
+/* The first byte is reserved for future use. */
+precision  = AV_RB8(buf + 1);/* size of coefficients */
+qtable_len = AV_RB16(buf + 2);   /* length in bytes */
+buf += 4;
+len -= 4;
 
-if (q == 255 && qtable_len == 0) {
-av_log(ctx, AV_LOG_ERROR,
-   "Invalid RTP/JPEG packet. Quantization tables not 
found.\n");
-return AVERROR_INVALIDDATA;
-}
+if (precision)
+av_log(ctx, AV_LOG_WARNING, "Only 8-bit precision is 
supported.\n");
 
-if (qtable_len > 0) {
-if (len < qtable_len) {
-av_log(ctx, AV_LOG_ERROR, "Too short RTP/JPEG packet.\n");
+if (q == 255 && qtable_len == 0) {
+av_log(ctx, AV_LOG_ERROR,
+   "Invalid RTP/JPEG packet. Quantization tables not 
found.\n");
 return AVERROR_INVALIDDATA;
 }
-qtables = buf;
-buf += qtable_len;
-len -= qtable_len;
-}
-}
 
-if (off == 0) {
-/* Start of JPEG data packet. */
-uint8_t new_qtables[128];
-uint8_t hdr[1024];
+if (qtable_len > 0) {
+if (len < qtable_len) {
+av_log(ctx, AV_LOG_ERROR, "Too short RTP/JPEG packet.\n");
+return AVERROR_INVALIDDATA;
+}
+qtables = buf;
+buf += qtable_len;
+len -= qtable_len;
+}
+}
 
 /* Skip the current frame in case of the end packet
  * has been lost somewhere. */

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

[libav-commits] rtpdec_jpeg: Write the DHT section properly

2012-09-12 Thread Martin Storsjö
Module: libav
Branch: master
Commit: 7ef4323405fae8f62732111b747d585ef9c786c7

Author:Martin Storsjö 
Committer: Martin Storsjö 
Date:  Tue Sep 11 11:03:05 2012 +0300

rtpdec_jpeg: Write the DHT section properly

Currently the size header of the generated DHT section is
incorrect, making the mjpeg decoder just skip it. Since the
written huffman tables are the default ones, this failure had
gone undetected.

Signed-off-by: Martin Storsjö 

---

 libavformat/rtpdec_jpeg.c |   33 -
 1 files changed, 20 insertions(+), 13 deletions(-)

diff --git a/libavformat/rtpdec_jpeg.c b/libavformat/rtpdec_jpeg.c
index 671763d..19ecbf4 100644
--- a/libavformat/rtpdec_jpeg.c
+++ b/libavformat/rtpdec_jpeg.c
@@ -76,13 +76,12 @@ static void jpeg_free_context(PayloadContext *jpeg)
 av_free(jpeg);
 }
 
-static void jpeg_create_huffman_table(PutBitContext *p, int table_class,
-  int table_id, const uint8_t *bits_table,
-  const uint8_t *value_table)
+static int jpeg_create_huffman_table(PutBitContext *p, int table_class,
+ int table_id, const uint8_t *bits_table,
+ const uint8_t *value_table)
 {
 int i, n = 0;
 
-put_bits(p, 8, 0);
 put_bits(p, 4, table_class);
 put_bits(p, 4, table_id);
 
@@ -94,12 +93,15 @@ static void jpeg_create_huffman_table(PutBitContext *p, int 
table_class,
 for (i = 0; i < n; i++) {
 put_bits(p, 8, value_table[i]);
 }
+return n + 17;
 }
 
 static int jpeg_create_header(uint8_t *buf, int size, uint32_t type, uint32_t 
w,
   uint32_t h, const uint8_t *qtable, int nb_qtable)
 {
 PutBitContext pbc;
+uint8_t *dht_size_ptr;
+int dht_size;
 
 init_put_bits(&pbc, buf, size);
 
@@ -142,15 +144,20 @@ static int jpeg_create_header(uint8_t *buf, int size, 
uint32_t type, uint32_t w,
 
 /* DHT */
 put_marker(&pbc, DHT);
-
-jpeg_create_huffman_table(&pbc, 0, 0, avpriv_mjpeg_bits_dc_luminance,
-  avpriv_mjpeg_val_dc);
-jpeg_create_huffman_table(&pbc, 0, 1, avpriv_mjpeg_bits_dc_chrominance,
-  avpriv_mjpeg_val_dc);
-jpeg_create_huffman_table(&pbc, 1, 0, avpriv_mjpeg_bits_ac_luminance,
-  avpriv_mjpeg_val_ac_luminance);
-jpeg_create_huffman_table(&pbc, 1, 1, avpriv_mjpeg_bits_ac_chrominance,
-  avpriv_mjpeg_val_ac_chrominance);
+flush_put_bits(&pbc);
+dht_size_ptr = put_bits_ptr(&pbc);
+put_bits(&pbc, 16, 0);
+
+dht_size  = 2;
+dht_size += jpeg_create_huffman_table(&pbc, 0, 
0,avpriv_mjpeg_bits_dc_luminance,
+  avpriv_mjpeg_val_dc);
+dht_size += jpeg_create_huffman_table(&pbc, 0, 1, 
avpriv_mjpeg_bits_dc_chrominance,
+  avpriv_mjpeg_val_dc);
+dht_size += jpeg_create_huffman_table(&pbc, 1, 0, 
avpriv_mjpeg_bits_ac_luminance,
+  avpriv_mjpeg_val_ac_luminance);
+dht_size += jpeg_create_huffman_table(&pbc, 1, 1, 
avpriv_mjpeg_bits_ac_chrominance,
+  avpriv_mjpeg_val_ac_chrominance);
+AV_WB16(dht_size_ptr, dht_size);
 
 /* SOF0 */
 put_marker(&pbc, SOF0);

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