[FFmpeg-devel] [PATCH] force WINAPI_FAMILY to WINAPI_FAMILY_DESKTOP_APP to use DVXA

2015-07-26 Thread Steve Lhomme
The struct definitions in dxva.h, which are necessary in order to
actually use d3d11va, are hidden when WINAPI_FAMILY targets Windows Phone
or WindowsRT.

Building with WINAPI_FAMILY=WINAPI_FAMILY_DESKTOP_APP is disallowed
when targeting ARM. ("Compiling Desktop applications for the ARM
platform is not supported.") So we set _CRT_BUILD_DESKTOP_APP to 0
to tell the runtime not to detect some issues with this mismatching.

The same tweaks to detect if the API is available is done in dxva2_internal.h
when compiling each DXVA2/D3D11VA decoders.
---
 configure   | 2 +-
 libavcodec/dxva2_internal.h | 7 +++
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/configure b/configure
index 5ef2e0d..1ea94b3 100755
--- a/configure
+++ b/configure
@@ -4264,7 +4264,7 @@ check_lib2 "windows.h psapi.h" GetProcessMemoryInfo 
-lpsapi
 
 check_struct "sys/time.h sys/resource.h" "struct rusage" ru_maxrss
 
-check_type "windows.h dxva.h" "DXVA_PicParams_HEVC"
+check_type "windows.h dxva.h" "DXVA_PicParams_HEVC" 
-DWINAPI_FAMILY=WINAPI_FAMILY_DESKTOP_APP -D_CRT_BUILD_DESKTOP_APP=0
 check_type "windows.h d3d11.h" "ID3D11VideoDecoder"
 check_type "d3d9.h dxva2api.h" DXVA2_ConfigPictureDecode -D_WIN32_WINNT=0x0600
 
diff --git a/libavcodec/dxva2_internal.h b/libavcodec/dxva2_internal.h
index 3b651a4..d2896aa 100644
--- a/libavcodec/dxva2_internal.h
+++ b/libavcodec/dxva2_internal.h
@@ -27,6 +27,9 @@
 
 #include "config.h"
 
+/* define the proper COM entries before forcing desktop APIs */
+#include 
+
 #if CONFIG_DXVA2
 #include "dxva2.h"
 #endif
@@ -34,6 +37,10 @@
 #include "d3d11va.h"
 #endif
 #if HAVE_DXVA_H
+/* dxva.h defines nothing otherwise but it works */
+#undef WINAPI_FAMILY
+#define WINAPI_FAMILY WINAPI_FAMILY_DESKTOP_APP
+#define _CRT_BUILD_DESKTOP_APP 0
 #include 
 #endif
 
-- 
2.4.5

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] avcodec/dvbsubdec: Add option to select when to computer clut (always/never/"if needed")

2015-07-26 Thread Michael Niedermayer
From: Michael Niedermayer 

Signed-off-by: Michael Niedermayer 
---
 libavcodec/dvbsubdec.c |4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/libavcodec/dvbsubdec.c b/libavcodec/dvbsubdec.c
index 9f59b72..e3b72ab 100644
--- a/libavcodec/dvbsubdec.c
+++ b/libavcodec/dvbsubdec.c
@@ -237,6 +237,7 @@ typedef struct DVBSubContext {
 int time_out;
 int compute_edt; /**< if 1 end display time calculated using pts
   if 0 (Default) calculated using time out */
+int compute_clut;
 int64_t prev_start;
 DVBSubRegion *region_list;
 DVBSubCLUT   *clut_list;
@@ -912,7 +913,7 @@ static int save_subtitle_set(AVCodecContext *avctx, 
AVSubtitle *sub, int *got_ou
 
 memcpy(rect->pict.data[0], region->pbuf, region->buf_size);
 
-if (clut == &default_clut)
+if ((clut == &default_clut && ctx->compute_clut == -1) || 
ctx->compute_clut == 1)
 compute_default_clut(&rect->pict, rect->w, rect->h);
 
 i++;
@@ -1706,6 +1707,7 @@ end:
 #define DS AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_SUBTITLE_PARAM
 static const AVOption options[] = {
 {"compute_edt", "compute end of time using pts or timeout", 
offsetof(DVBSubContext, compute_edt), FF_OPT_TYPE_INT, {.i64 = 0}, 0, 1, DS},
+{"compute_clut", "compute clut when not available(-1) or always(1) or 
never(0)", offsetof(DVBSubContext, compute_clut), FF_OPT_TYPE_INT, {.i64 = -1}, 
-1, 1, DS},
 {NULL}
 };
 static const AVClass dvbsubdec_class = {
-- 
1.7.9.5

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] movtextdec.c: Add support for fontsize

2015-07-26 Thread Philip Langdale
On Fri, 24 Jul 2015 14:35:16 +0530
Niklesh Lalwani  wrote:

> From: Niklesh 
> 
> Add support for fontsize in style records. The patch uses reset to
> directly change back to default style instead of using closing tags,
> since we are not handling the default styles right now.
> 
> Signed-off-by: Niklesh 
> ---
>  libavcodec/movtextdec.c | 14 ++
>  1 file changed, 6 insertions(+), 8 deletions(-)
> 
> diff --git a/libavcodec/movtextdec.c b/libavcodec/movtextdec.c
> index ca02107..869358c 100644
> --- a/libavcodec/movtextdec.c
> +++ b/libavcodec/movtextdec.c
> @@ -39,6 +39,7 @@ typedef struct {
>  uint16_t style_start;
>  uint16_t style_end;
>  uint8_t style_flag;
> +uint8_t fontsize;
>  } StyleBox;
>  
>  typedef struct {
> @@ -120,13 +121,14 @@ static int decode_styl(const uint8_t *tsmb,
> MovTextContext *m, AVPacket *avpkt) // fontID = AV_RB16(tsmb);
>  tsmb += 2;
>  m->s_temp->style_flag = AV_RB8(tsmb);
> +tsmb++;
> +m->s_temp->fontsize = AV_RB8(tsmb);
>  av_dynarray_add(&m->s, &m->count_s, m->s_temp);
>  if(!m->s) {
>  mov_text_cleanup(m);
>  return AVERROR(ENOMEM);
>  }
> -// fontsize = AV_RB8(tsmb);
> -tsmb += 2;
> +tsmb++;
>  // text-color-rgba
>  tsmb += 4;
>  }
> @@ -150,12 +152,7 @@ static int text_to_ass(AVBPrint *buf, const char
> *text, const char *text_end, if (m->box_flags & STYL_BOX) {
>  for (i = 0; i < m->style_entries; i++) {
>  if (m->s[i]->style_flag && text_pos ==
> m->s[i]->style_end) {
> -if (m->s[i]->style_flag & STYLE_FLAG_BOLD)
> -av_bprintf(buf, "{\\b0}");
> -if (m->s[i]->style_flag & STYLE_FLAG_ITALIC)
> -av_bprintf(buf, "{\\i0}");
> -if (m->s[i]->style_flag & STYLE_FLAG_UNDERLINE)
> -av_bprintf(buf, "{\\u0}");
> +av_bprintf(buf, "{\\r}");
>  }
>  }
>  for (i = 0; i < m->style_entries; i++) {
> @@ -166,6 +163,7 @@ static int text_to_ass(AVBPrint *buf, const char
> *text, const char *text_end, av_bprintf(buf, "{\\i1}");
>  if (m->s[i]->style_flag & STYLE_FLAG_UNDERLINE)
>  av_bprintf(buf, "{\\u1}");
> +av_bprintf(buf, "{\\fs%d}", m->s[i]->fontsize);
>  }
>  }
>  }

Pushed, thanks.


--phil
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] ffplay: Use sws_scale to scale subtitles

2015-07-26 Thread Michael Niedermayer
From: Michael Niedermayer 

Fixes some files from Ticket679

This also changes subtitles to 4:2:0 matching the output format and thus
simplifying the blend code.
This restricts placement to the chroma sample resolution though, speak up
if you consider this a problem, say so, the code could be changed to use
YUV444 for subtitles and scaling them down while blending, this would be
slower though.
The current code only uses a single swscale context and reinitializes it
as needed, this could be changed as well if needed

Signed-off-by: Michael Niedermayer 
---
 ffplay.c |  275 ++
 1 file changed, 62 insertions(+), 213 deletions(-)

diff --git a/ffplay.c b/ffplay.c
index 58034c6..98be072 100644
--- a/ffplay.c
+++ b/ffplay.c
@@ -278,6 +278,7 @@ typedef struct VideoState {
 #if !CONFIG_AVFILTER
 struct SwsContext *img_convert_ctx;
 #endif
+struct SwsContext *sub_convert_ctx;
 SDL_Rect last_display_rect;
 int eof;
 
@@ -829,229 +830,50 @@ static void fill_border(int xleft, int ytop, int width, 
int height, int x, int y
 #define ALPHA_BLEND(a, oldp, newp, s)\
 oldp << s) * (255 - (a))) + (newp * (a))) / (255 << s))
 
-#define RGBA_IN(r, g, b, a, s)\
-{\
-unsigned int v = ((const uint32_t *)(s))[0];\
-a = (v >> 24) & 0xff;\
-r = (v >> 16) & 0xff;\
-g = (v >> 8) & 0xff;\
-b = v & 0xff;\
-}
-
-#define YUVA_IN(y, u, v, a, s, pal)\
-{\
-unsigned int val = ((const uint32_t *)(pal))[*(const uint8_t*)(s)];\
-a = (val >> 24) & 0xff;\
-y = (val >> 16) & 0xff;\
-u = (val >> 8) & 0xff;\
-v = val & 0xff;\
-}
-
-#define YUVA_OUT(d, y, u, v, a)\
-{\
-((uint32_t *)(d))[0] = (a << 24) | (y << 16) | (u << 8) | v;\
-}
 
 
 #define BPP 1
 
 static void blend_subrect(AVPicture *dst, const AVSubtitleRect *rect, int 
imgw, int imgh)
 {
-int wrap, wrap3, width2, skip2;
-int y, u, v, a, u1, v1, a1, w, h;
+int x, y, Y, U, V, A;
 uint8_t *lum, *cb, *cr;
-const uint8_t *p;
-const uint32_t *pal;
 int dstx, dsty, dstw, dsth;
+const AVPicture *src = &rect->pict;
 
 dstw = av_clip(rect->w, 0, imgw);
 dsth = av_clip(rect->h, 0, imgh);
 dstx = av_clip(rect->x, 0, imgw - dstw);
 dsty = av_clip(rect->y, 0, imgh - dsth);
-lum = dst->data[0] + dsty * dst->linesize[0];
-cb  = dst->data[1] + (dsty >> 1) * dst->linesize[1];
-cr  = dst->data[2] + (dsty >> 1) * dst->linesize[2];
-
-width2 = ((dstw + 1) >> 1) + (dstx & ~dstw & 1);
-skip2 = dstx >> 1;
-wrap = dst->linesize[0];
-wrap3 = rect->pict.linesize[0];
-p = rect->pict.data[0];
-pal = (const uint32_t *)rect->pict.data[1];  /* Now in YCrCb! */
-
-if (dsty & 1) {
-lum += dstx;
-cb += skip2;
-cr += skip2;
-
-if (dstx & 1) {
-YUVA_IN(y, u, v, a, p, pal);
-lum[0] = ALPHA_BLEND(a, lum[0], y, 0);
-cb[0] = ALPHA_BLEND(a >> 2, cb[0], u, 0);
-cr[0] = ALPHA_BLEND(a >> 2, cr[0], v, 0);
-cb++;
-cr++;
+lum = dst->data[0] + dstx + dsty * dst->linesize[0];
+cb  = dst->data[1] + dstx/2 + (dsty >> 1) * dst->linesize[1];
+cr  = dst->data[2] + dstx/2 + (dsty >> 1) * dst->linesize[2];
+
+for (y = 0; ydata[0][x + y*src->linesize[0]];
+A = src->data[3][x + y*src->linesize[3]];
+lum[0] = ALPHA_BLEND(A, lum[0], Y, 0);
 lum++;
-p += BPP;
-}
-for (w = dstw - (dstx & 1); w >= 2; w -= 2) {
-YUVA_IN(y, u, v, a, p, pal);
-u1 = u;
-v1 = v;
-a1 = a;
-lum[0] = ALPHA_BLEND(a, lum[0], y, 0);
-
-YUVA_IN(y, u, v, a, p + BPP, pal);
-u1 += u;
-v1 += v;
-a1 += a;
-lum[1] = ALPHA_BLEND(a, lum[1], y, 0);
-cb[0] = ALPHA_BLEND(a1 >> 2, cb[0], u1, 1);
-cr[0] = ALPHA_BLEND(a1 >> 2, cr[0], v1, 1);
-cb++;
-cr++;
-p += 2 * BPP;
-lum += 2;
-}
-if (w) {
-YUVA_IN(y, u, v, a, p, pal);
-lum[0] = ALPHA_BLEND(a, lum[0], y, 0);
-cb[0] = ALPHA_BLEND(a >> 2, cb[0], u, 0);
-cr[0] = ALPHA_BLEND(a >> 2, cr[0], v, 0);
-p++;
-lum++;
-}
-p += wrap3 - dstw * BPP;
-lum += wrap - dstw - dstx;
-cb += dst->linesize[1] - width2 - skip2;
-cr += dst->linesize[2] - width2 - skip2;
-}
-for (h = dsth - (dsty & 1); h >= 2; h -= 2) {
-lum += dstx;
-cb += skip2;
-cr += skip2;
-
-if (dstx & 1) {
-YUVA_IN(y, u, v, a, p, pal);
-u1 = u;
-v1 = v;
-a1 = a;
-lum[0] = ALPHA_BLEND(a, lum[0], y, 0);
-p += wrap3;
-lum += wrap;
-YUVA_IN(y, u, v, a, p, pal);
-u1 += u;
-v1 += v;
-a1 += a;
-lum[0] = ALPHA_BLEND(a, 

Re: [FFmpeg-devel] [PATCH 2/2] mcfps filter WIP

2015-07-26 Thread wm4
On Fri, 24 Jul 2015 20:50:56 +0200
Michael Niedermayer  wrote:

> Works well with some scenes, works really not well with others
> More work needed
> if you can improve it, i would not be unhappy
> 
> this should not be optimized yet except trivial things, first the code
> should work well then it should be made to work fast
> 
> Signed-off-by: Michael Niedermayer 
> ---
>  libavcodec/internal.h|3 +
>  libavcodec/snow.c|   30 ++
>  libavcodec/utils.c   |   10 +
>  libavfilter/Makefile |1 +
>  libavfilter/allfilters.c |1 +
>  libavfilter/vf_mcfps.c   |  853 
> ++
>  6 files changed, 898 insertions(+)
>  create mode 100644 libavfilter/vf_mcfps.c
> 


> diff --git a/libavcodec/utils.c b/libavcodec/utils.c
> index d926a26..8bc7b65 100644
> --- a/libavcodec/utils.c
> +++ b/libavcodec/utils.c
> @@ -3906,3 +3906,13 @@ const uint8_t *avpriv_find_start_code(const uint8_t 
> *av_restrict p,
>  
>  return p + 4;
>  }
> +
> +int avpriv_get_mvs(AVCodecContext *avctx, int16_t (*mvs)[2], int8_t *refs, 
> int width, int height)
> +{
> +switch (avctx->codec_id) {
> +case AV_CODEC_ID_SNOW:
> +return ff_get_mvs_snow(avctx, mvs, refs, width, height);
> +default:
> +return AVERROR(EINVAL);
> +}
> +}

> diff --git a/libavfilter/vf_mcfps.c b/libavfilter/vf_mcfps.c
> new file mode 100644
> index 000..784275d
> --- /dev/null
> +++ b/libavfilter/vf_mcfps.c

> +static int extract_mvs(MCFPSContext *mcfps, InputFrame *f, int dir)
> +{
> +if (!f->mv[dir])
> +f->mv[dir] = av_malloc(mcfps->b_width * mcfps->b_height * 
> sizeof(*f->mv[0]));
> +if (!f->ref[dir])
> +f->ref[dir] = av_malloc(mcfps->b_width * mcfps->b_height * 
> sizeof(*f->ref[0]));
> +if (!f->mv[dir] || !f->ref[0])
> +return AVERROR(ENOMEM);
> +
> +return avpriv_get_mvs(mcfps->avctx_enc[dir],
> +f->mv[dir],
> +f->ref[dir],
> +mcfps->b_width,
> +mcfps->b_height);
> +}

That reminds me of MPlayer's filter using libavcodec internals. I'm
very against this. It's a very awful form of code reuse.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] avcodec/dvbsubdec: Add option to select when to computer clut (always/never/"if needed")

2015-07-26 Thread Anshul
On July 26, 2015 10:33:22 PM IST, Michael Niedermayer  wrote:
>From: Michael Niedermayer 
>
>Signed-off-by: Michael Niedermayer 
>---
> libavcodec/dvbsubdec.c |4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
>diff --git a/libavcodec/dvbsubdec.c b/libavcodec/dvbsubdec.c
>index 9f59b72..e3b72ab 100644
>--- a/libavcodec/dvbsubdec.c
>+++ b/libavcodec/dvbsubdec.c
>@@ -237,6 +237,7 @@ typedef struct DVBSubContext {
> int time_out;
> int compute_edt; /**< if 1 end display time calculated using pts
>   if 0 (Default) calculated using time out */
>+int compute_clut;
> int64_t prev_start;
> DVBSubRegion *region_list;
> DVBSubCLUT   *clut_list;
>@@ -912,7 +913,7 @@ static int save_subtitle_set(AVCodecContext *avctx,
>AVSubtitle *sub, int *got_ou
> 
>memcpy(rect->pict.data[0], region->pbuf, region->buf_size);
> 
>-if (clut == &default_clut)
>+if ((clut == &default_clut && ctx->compute_clut == -1) ||
>ctx->compute_clut == 1)
> compute_default_clut(&rect->pict, rect->w, rect->h);
> 
> i++;
>@@ -1706,6 +1707,7 @@ end:
> #define DS AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_SUBTITLE_PARAM
> static const AVOption options[] = {
>{"compute_edt", "compute end of time using pts or timeout",
>offsetof(DVBSubContext, compute_edt), FF_OPT_TYPE_INT, {.i64 = 0}, 0,
>1, DS},
>+{"compute_clut", "compute clut when not available(-1) or always(1)
>or never(0)", offsetof(DVBSubContext, compute_clut), FF_OPT_TYPE_INT,
>{.i64 = -1}, -1, 1, DS},
> {NULL}
> };
> static const AVClass dvbsubdec_class = {
>-- 
>1.7.9.5
>
>___
>ffmpeg-devel mailing list
>ffmpeg-devel@ffmpeg.org
>http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


LGTM.

-Anshul

-- 
Sent from my Android device with K-9 Mail. Please excuse my brevity.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] force WINAPI_FAMILY to WINAPI_FAMILY_DESKTOP_APP to use DVXA

2015-07-26 Thread Michael Niedermayer
On Sun, Jul 26, 2015 at 01:35:47PM +0200, Steve Lhomme wrote:
> The struct definitions in dxva.h, which are necessary in order to
> actually use d3d11va, are hidden when WINAPI_FAMILY targets Windows Phone
> or WindowsRT.
> 
> Building with WINAPI_FAMILY=WINAPI_FAMILY_DESKTOP_APP is disallowed
> when targeting ARM. ("Compiling Desktop applications for the ARM
> platform is not supported.") So we set _CRT_BUILD_DESKTOP_APP to 0
> to tell the runtime not to detect some issues with this mismatching.
> 
> The same tweaks to detect if the API is available is done in dxva2_internal.h
> when compiling each DXVA2/D3D11VA decoders.
> ---
>  configure   | 2 +-
>  libavcodec/dxva2_internal.h | 7 +++
>  2 files changed, 8 insertions(+), 1 deletion(-)

applied

thanks

[...]
-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Many things microsoft did are stupid, but not doing something just because
microsoft did it is even more stupid. If everything ms did were stupid they
would be bankrupt already.


signature.asc
Description: Digital signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] avcodec/dvbsubdec: Add option to select when to computer clut (always/never/"if needed")

2015-07-26 Thread Michael Niedermayer
On Mon, Jul 27, 2015 at 01:38:53AM +0530, Anshul wrote:
> On July 26, 2015 10:33:22 PM IST, Michael Niedermayer  
> wrote:
> >From: Michael Niedermayer 
> >
> >Signed-off-by: Michael Niedermayer 
> >---
> > libavcodec/dvbsubdec.c |4 +++-
> > 1 file changed, 3 insertions(+), 1 deletion(-)
> >
> >diff --git a/libavcodec/dvbsubdec.c b/libavcodec/dvbsubdec.c
> >index 9f59b72..e3b72ab 100644
> >--- a/libavcodec/dvbsubdec.c
> >+++ b/libavcodec/dvbsubdec.c
> >@@ -237,6 +237,7 @@ typedef struct DVBSubContext {
> > int time_out;
> > int compute_edt; /**< if 1 end display time calculated using pts
> >   if 0 (Default) calculated using time out */
> >+int compute_clut;
> > int64_t prev_start;
> > DVBSubRegion *region_list;
> > DVBSubCLUT   *clut_list;
> >@@ -912,7 +913,7 @@ static int save_subtitle_set(AVCodecContext *avctx,
> >AVSubtitle *sub, int *got_ou
> > 
> >memcpy(rect->pict.data[0], region->pbuf, region->buf_size);
> > 
> >-if (clut == &default_clut)
> >+if ((clut == &default_clut && ctx->compute_clut == -1) ||
> >ctx->compute_clut == 1)
> > compute_default_clut(&rect->pict, rect->w, rect->h);
> > 
> > i++;
> >@@ -1706,6 +1707,7 @@ end:
> > #define DS AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_SUBTITLE_PARAM
> > static const AVOption options[] = {
> >{"compute_edt", "compute end of time using pts or timeout",
> >offsetof(DVBSubContext, compute_edt), FF_OPT_TYPE_INT, {.i64 = 0}, 0,
> >1, DS},
> >+{"compute_clut", "compute clut when not available(-1) or always(1)
> >or never(0)", offsetof(DVBSubContext, compute_clut), FF_OPT_TYPE_INT,
> >{.i64 = -1}, -1, 1, DS},
> > {NULL}
> > };
> > static const AVClass dvbsubdec_class = {
> >-- 
> >1.7.9.5
> >
> >___
> >ffmpeg-devel mailing list
> >ffmpeg-devel@ffmpeg.org
> >http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> 
> LGTM.

applied

thanks

[...]
-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Breaking DRM is a little like attempting to break through a door even
though the window is wide open and the only thing in the house is a bunch
of things you dont want and which you would get tomorrow for free anyway


signature.asc
Description: Digital signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] Add support for Audible AA files

2015-07-26 Thread Vesselin Bontchev
Hi!

This patch adds support for Audible AA files.

Audible samples can be obtained from,

https://gitlab.com/vesselin.bontchev/audible-samples/tree/master
https://samples.ffmpeg.org/audible/

Currently, this code generates corrupt audio output (in some places, and 
deterministically).

By posting this patch, I am hoping to get some early feedback, and help in 
making this work.

Thanks,
VesselinFrom ba73543efc3fdc4b5c61e9cb56f998d748716e00 Mon Sep 17 00:00:00 2001
From: Vesselin Bontchev 
Date: Sun, 19 Jul 2015 23:16:36 +0200
Subject: [PATCH] Add support for Audible AA files

https://en.wikipedia.org/wiki/Audible.com#Quality
---
 doc/demuxers.texi|  10 ++
 doc/general.texi |   2 +
 libavformat/Makefile |   1 +
 libavformat/aadec.c  | 381 +++
 libavformat/allformats.c |   1 +
 5 files changed, 395 insertions(+)
 create mode 100644 libavformat/aadec.c

diff --git a/doc/demuxers.texi b/doc/demuxers.texi
index e45e1af..df95233 100644
--- a/doc/demuxers.texi
+++ b/doc/demuxers.texi
@@ -18,6 +18,16 @@ enabled demuxers.
 
 The description of some of the currently available demuxers follows.
 
+@section aa
+
+Audible Format 2, 3, and 4 demuxer.
+
+This demuxer is used to demux Audible Format 2, 3, and 4 (.aa) files.
+
+@example
+ffmpeg -v debug -i input.aa -c:a copy output.wav
+@end example
+
 @section applehttp
 
 Apple HTTP Live Streaming demuxer.
diff --git a/doc/general.texi b/doc/general.texi
index a260e79..2b782e0 100644
--- a/doc/general.texi
+++ b/doc/general.texi
@@ -228,6 +228,8 @@ library:
 @item 8088flex TMV  @tab   @tab X
 @item AAX   @tab   @tab X
 @tab Audible Enhanced Audio format, used in audiobooks.
+@item AA@tab   @tab X
+@tab Audible Format 2, 3, and 4, used in audiobooks.
 @item ACT Voice @tab   @tab X
 @tab contains G.729 audio
 @item Adobe Filmstrip   @tab X @tab X
diff --git a/libavformat/Makefile b/libavformat/Makefile
index cc73fd8..8405f8d 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -395,6 +395,7 @@ OBJS-$(CONFIG_RTSP_DEMUXER)  += rtsp.o rtspdec.o httpauth.o \
 OBJS-$(CONFIG_RTSP_MUXER)+= rtsp.o rtspenc.o httpauth.o \
 urldecode.o
 OBJS-$(CONFIG_SAMI_DEMUXER)  += samidec.o subtitles.o
+OBJS-$(CONFIG_AA_DEMUXER)+= aadec.o
 OBJS-$(CONFIG_SAP_DEMUXER)   += sapdec.o
 OBJS-$(CONFIG_SAP_MUXER) += sapenc.o
 OBJS-$(CONFIG_SBG_DEMUXER)   += sbgdec.o
diff --git a/libavformat/aadec.c b/libavformat/aadec.c
new file mode 100644
index 000..bd994e8
--- /dev/null
+++ b/libavformat/aadec.c
@@ -0,0 +1,381 @@
+/*
+ * Audible AA demuxer
+ * Copyright (c) 2015 Vesselin Bontchev
+ *
+ * Inspired by https://github.com/jteeuwen/audible, and
+ * https://code.google.com/p/pyaudibletags/source projects.
+ *
+ * See https://en.wikipedia.org/wiki/Audible.com#Quality for
+ * format details.
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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 FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "avformat.h"
+#include "internal.h"
+#include "libavutil/intreadwrite.h"
+#include "libavutil/tea.h"
+#include "libavutil/fifo.h"
+#include "libavutil/opt.h"
+
+#define AA_MAGIC 1469084982 /* this identifies an audible .aa file */
+#define MAX_CODEC_SECOND_SIZE 3982
+#define MAX_TOC_ENTRIES 64
+#define TEA_BLOCK_SIZE 8
+
+typedef struct AADemuxContext {
+int64_t data_end;
+uint32_t HeaderSeed;
+uint32_t Filesize;
+uint32_t Magic;
+uint32_t tocSize;
+uint32_t npairs;
+union {
+unsigned char key[16];
+uint32_t part[4];
+} HeaderKey;
+uint32_t TOC[MAX_TOC_ENTRIES][2];
+
+void *aa_fixed_key;
+int aa_fixed_key_size;
+uint32_t start;
+uint32_t end;
+int32_t codec_second_size;
+char codec_name[64];
+struct AVTEA *tea_ctx;
+uint8_t final_key[16];
+int64_t current_chapter_size;
+int64_t current_codec_second_size;
+uint32_t trailing_bytes;
+int64_t total_parsed;
+struct AVFifoBuffer *cbuf;
+int chapter_idx;
+} AADemuxContext;
+
+static int32_t GetSecondSizeByCodecID(char *codec_name)
+{
+int32_t result = 0;
+
+if (!strcmp(codec_nam

Re: [FFmpeg-devel] [PATCH] Add support for Audible AA files

2015-07-26 Thread Carl Eugen Hoyos
Vesselin Bontchev  yandex.com> writes:

> This patch adds support for Audible AA files.

> +uint32_t Magic;

This one is unused, please remove it.
And please make all others lower case.
And please avoid CamelCase, use_underscores_instead.
(I actually prefer CamelCase but it is very unusual in 
FFmpeg.)

> +union {
> +unsigned char key[16];
> +uint32_t part[4];
> +} HeaderKey;

Is this useful?
(I did not really check.)

> +} else if (!strcmp(codec_name, "acelp85")) {
> +// 0xC00C
> +result = 2000;
> +} else if (!strcmp(codec_name, "acelp85")) {

If I don't miss anything, something is wrong here...

And I think you can use memcmp() here.

> +static void readString(AVIOContext *pb, int size, char *output)
> +{
> +avio_read(pb, output, size);
> +}

This does not look useful.

> +unsigned char dst[8];
> +unsigned char src[8];

This is uint8_t in tea.h, I suggest you use the 
same type here.

> +avio_rb32(pb); // unidentified integer

Please use avio_skip().

> +memcpy(output + 0, "\x00\x00",2); // purely for padding purposes

This looks ugly, should be output[0]=output[1]=0; 
or similar imo.

> +return AVERROR_DECODER_NOT_FOUND;

This should be AVERROR_INVALIDDATA.

> +if (AV_RB32(buf+4) != AA_MAGIC)
> +return AVPROBE_SCORE_EXTENSION;

return 0

> +return AVPROBE_SCORE_MAX;

return MAX/2 for 32bit.

Do you check the length of all strings you are 
reading from the file?

Thank you for your patch, Carl Eugen

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] ffmpeg: Implement support for seeking relative to EOF

2015-07-26 Thread Michael Niedermayer
From: Michael Niedermayer 

Fixes Ticket227

Signed-off-by: Michael Niedermayer 
---
 ffmpeg.h |1 +
 ffmpeg_opt.c |6 ++
 2 files changed, 7 insertions(+)

diff --git a/ffmpeg.h b/ffmpeg.h
index e43c985..38e7784 100644
--- a/ffmpeg.h
+++ b/ffmpeg.h
@@ -92,6 +92,7 @@ typedef struct OptionsContext {
 
 /* input/output options */
 int64_t start_time;
+int64_t start_time_eof;
 int seek_timestamp;
 const char *format;
 
diff --git a/ffmpeg_opt.c b/ffmpeg_opt.c
index ceebcfe..21477ed 100644
--- a/ffmpeg_opt.c
+++ b/ffmpeg_opt.c
@@ -156,6 +156,7 @@ static void init_options(OptionsContext *o)
 o->stop_time = INT64_MAX;
 o->mux_max_delay  = 0.7;
 o->start_time = AV_NOPTS_VALUE;
+o->start_time_eof = AV_NOPTS_VALUE;
 o->recording_time = INT64_MAX;
 o->limit_filesize = UINT64_MAX;
 o->chapters_input_file = INT_MAX;
@@ -933,6 +934,8 @@ static int open_input_file(OptionsContext *o, const char 
*filename)
 }
 }
 
+if (o->start_time_eof != AV_NOPTS_VALUE && ic->duration>0)
+o->start_time = o->start_time_eof + ic->duration;
 timestamp = (o->start_time == AV_NOPTS_VALUE) ? 0 : o->start_time;
 /* add the stream start time */
 if (!o->seek_timestamp && ic->start_time != AV_NOPTS_VALUE)
@@ -3019,6 +3022,9 @@ const OptionDef options[] = {
 { "ss", HAS_ARG | OPT_TIME | OPT_OFFSET |
 OPT_INPUT | OPT_OUTPUT,  { .off = 
OFFSET(start_time) },
 "set the start time offset", "time_off" },
+{ "sseof",  HAS_ARG | OPT_TIME | OPT_OFFSET |
+OPT_INPUT | OPT_OUTPUT,  { .off = 
OFFSET(start_time_eof) },
+"set the start time offset relative to EOF", "time_off" },
 { "seek_timestamp", HAS_ARG | OPT_INT | OPT_OFFSET |
 OPT_INPUT,   { .off = 
OFFSET(seek_timestamp) },
 "enable/disable seeking by timestamp with -ss" },
-- 
1.7.9.5

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] ffmpeg: Implement support for seeking relative to EOF

2015-07-26 Thread Timothy Gu
On 7/27/15, Michael Niedermayer  wrote:
> From: Michael Niedermayer 
>
> Fixes Ticket227
>
> Signed-off-by: Michael Niedermayer 
> ---
>  ffmpeg.h |1 +
>  ffmpeg_opt.c |6 ++
>  2 files changed, 7 insertions(+)

docs missing

[…]

Timothy
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH 1/2] ffmpeg: reset tty state correctly

2015-07-26 Thread Ganesh Ajjanagadde
tty state was not being reset upon "hard" signals (SIGSEGV etc)
This resets tty state in such situations, fixes Ticket2964

Signed-off-by: Ganesh Ajjanagadde 
---
 ffmpeg.c | 38 --
 1 file changed, 28 insertions(+), 10 deletions(-)

diff --git a/ffmpeg.c b/ffmpeg.c
index 751c7d3..8b5a705 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -325,10 +325,29 @@ sigterm_handler(int sig)
 received_sigterm = sig;
 received_nb_signals++;
 term_exit_sigsafe();
-if(received_nb_signals > 3) {
-write(2/*STDERR_FILENO*/, "Received > 3 system signals, hard 
exiting\n",
-   strlen("Received > 3 system signals, hard 
exiting\n"));
 
+switch (sig) {
+/* 2 = STDERR_FILENO */
+case SIGSEGV:
+write(2, "Segmentation fault, hard exiting\n",
+  strlen("Segmentation fault, hard exiting\n"));
+abort();
+case SIGILL:
+write(2, "Invalid instruction, hard exiting\n",
+  strlen("Invalid instruction, hard exiting\n"));
+abort();
+case SIGFPE:
+write(2, "Arithmetic exception, hard exiting\n",
+  strlen("Arithmetic exception, hard exiting\n"));
+abort();
+break;
+default:
+break;
+}
+
+if(received_nb_signals > 3) {
+write(2, "Received > 3 system signals, hard exiting\n",
+  strlen("Received > 3 system signals, hard exiting\n"));
 exit(123);
 }
 }
@@ -370,11 +389,7 @@ void term_init(void)
 #if HAVE_TERMIOS_H
 if(!run_as_daemon){
 struct termios tty;
-int istty = 1;
-#if HAVE_ISATTY
-istty = isatty(0) && isatty(2);
-#endif
-if (istty && tcgetattr (0, &tty) == 0) {
+if (tcgetattr (0, &tty) == 0) {
 oldtty = tty;
 restore_tty = 1;
 
@@ -393,8 +408,11 @@ void term_init(void)
 }
 #endif
 
-signal(SIGINT , sigterm_handler); /* Interrupt (ANSI).*/
-signal(SIGTERM, sigterm_handler); /* Termination (ANSI).  */
+signal(SIGINT , sigterm_handler); /* Interrupt (ANSI).  */
+signal(SIGTERM, sigterm_handler); /* Termination (ANSI).*/
+signal(SIGSEGV, sigterm_handler); /* Segmentation fault (ANSI). */
+signal(SIGILL , sigterm_handler); /* Invalid instruction (ANSI).*/
+signal(SIGFPE , sigterm_handler); /* Arithmetic error (ANSI).   */
 #ifdef SIGXCPU
 signal(SIGXCPU, sigterm_handler);
 #endif
-- 
2.4.6

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH 2/2] ffmpeg: silence unused return value warnings

2015-07-26 Thread Ganesh Ajjanagadde
GCC throws a -Wunused-result for not checking return value
of write(); silence it

Signed-off-by: Ganesh Ajjanagadde 
---
 ffmpeg.c | 16 
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/ffmpeg.c b/ffmpeg.c
index 8b5a705..6f18ab8 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -329,16 +329,16 @@ sigterm_handler(int sig)
 switch (sig) {
 /* 2 = STDERR_FILENO */
 case SIGSEGV:
-write(2, "Segmentation fault, hard exiting\n",
-  strlen("Segmentation fault, hard exiting\n"));
+if(write(2, "Segmentation fault, hard exiting\n",
+  strlen("Segmentation fault, hard exiting\n"))){};
 abort();
 case SIGILL:
-write(2, "Invalid instruction, hard exiting\n",
-  strlen("Invalid instruction, hard exiting\n"));
+if(write(2, "Invalid instruction, hard exiting\n",
+  strlen("Invalid instruction, hard exiting\n"))){};
 abort();
 case SIGFPE:
-write(2, "Arithmetic exception, hard exiting\n",
-  strlen("Arithmetic exception, hard exiting\n"));
+if(write(2, "Arithmetic exception, hard exiting\n",
+  strlen("Arithmetic exception, hard exiting\n"))){};
 abort();
 break;
 default:
@@ -346,8 +346,8 @@ sigterm_handler(int sig)
 }
 
 if(received_nb_signals > 3) {
-write(2, "Received > 3 system signals, hard exiting\n",
-  strlen("Received > 3 system signals, hard exiting\n"));
+if(write(2, "Received > 3 system signals, hard exiting\n",
+  strlen("Received > 3 system signals, hard exiting\n"))){};
 exit(123);
 }
 }
-- 
2.4.6

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel