Re: [FFmpeg-devel] [PATCH] rl.h: Allocate temporary VLC tables instead of having them static.

2014-09-01 Thread Michael Niedermayer
On Mon, Sep 01, 2014 at 09:32:56AM +0200, Reimar Döffinger wrote:
 On 01.09.2014, at 02:35, Michael Niedermayer michae...@gmx.at wrote:
  On Sun, Aug 31, 2014 at 08:27:17PM +0200, Reimar Döffinger wrote:
  
  {
  int i, q;
  +VLC vlc;
  
  +init_vlc(vlc, 9, rl-n + 1, rl-table_vlc[0][1], 4, 2, 
  rl-table_vlc[0][0], 4, 2, 0);
  
  same issue here
  
  why do you change the code to dynamically allocate ?
 
 Because it ends up using and wasting memory for nothing at runtime if you 
 leave it static.
 And the size is a bit too large to do it on-stack I think.

maybe iam missing something but does it need more than 5kb ?
or is that considered too much for some supported platform ?


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

You can kill me, but you cannot change the truth.


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


Re: [FFmpeg-devel] [PATCH] rl.h: Allocate temporary VLC tables instead of having them static.

2014-09-01 Thread Reimar Döffinger
On 1 September 2014 12:05:00 CEST, Michael Niedermayer michae...@gmx.at wrote:
On Mon, Sep 01, 2014 at 09:32:56AM +0200, Reimar Döffinger wrote:
 On 01.09.2014, at 02:35, Michael Niedermayer michae...@gmx.at
wrote:
  On Sun, Aug 31, 2014 at 08:27:17PM +0200, Reimar Döffinger wrote:
  
  {
  int i, q;
  +VLC vlc;
  
  +init_vlc(vlc, 9, rl-n + 1, rl-table_vlc[0][1], 4, 2,
rl-table_vlc[0][0], 4, 2, 0);
  
  same issue here
  
  why do you change the code to dynamically allocate ?
 
 Because it ends up using and wasting memory for nothing at runtime if
you leave it static.
 And the size is a bit too large to do it on-stack I think.

maybe iam missing something but does it need more than 5kb ?
or is that considered too much for some supported platform ?

Something around 5kB, yes.
Though since I'd prefer to have it in the function I'd prefer to just make it 
something like always 1500 elements or so...
I for some reason though 4kB was the limit though, but if not I'd be happy to 
put it on stack instead!


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


[FFmpeg-devel] [PATCH] rl.h: Allocate temporary VLC tables instead of having them static.

2014-08-31 Thread Reimar Döffinger
Signed-off-by: Reimar Döffinger reimar.doeffin...@gmx.de
---
 libavcodec/mpeg12.c| 23 ---
 libavcodec/mpegvideo.c | 14 ++
 libavcodec/rl.h|  8 ++--
 3 files changed, 24 insertions(+), 21 deletions(-)

diff --git a/libavcodec/mpeg12.c b/libavcodec/mpeg12.c
index cb00baf..769bed7 100644
--- a/libavcodec/mpeg12.c
+++ b/libavcodec/mpeg12.c
@@ -70,22 +70,22 @@ static const uint8_t table_mb_btype[11][2] = {
 #define INIT_2D_VLC_RL(rl, static_size)\
 {\
 static RL_VLC_ELEM rl_vlc_table[static_size];\
-VLC tmp_vlc;\
-INIT_VLC_STATIC(tmp_vlc, TEX_VLC_BITS, rl.n + 2,\
-rl.table_vlc[0][1], 4, 2,\
-rl.table_vlc[0][0], 4, 2, static_size);\
-\
 rl.rl_vlc[0] = rl_vlc_table;\
-init_2d_vlc_rl(rl, tmp_vlc);\
+init_2d_vlc_rl(rl, static_size);\
 }
 
-static av_cold void init_2d_vlc_rl(RLTable *rl, const VLC *vlc)
+static av_cold void init_2d_vlc_rl(RLTable *rl, unsigned static_size)
 {
 int i;
-
-for (i = 0; i  vlc-table_size; i++) {
-int code = vlc-table[i][0];
-int len  = vlc-table[i][1];
+VLC vlc;
+init_vlc(vlc, TEX_VLC_BITS, rl-n + 2, rl-table_vlc[0][1], 4, 2, 
rl-table_vlc[0][0], 4, 2, 0);
+av_assert0(vlc.table_size = static_size);
+if (vlc.table_size != static_size)
+av_log(NULL, AV_LOG_ERROR, needed %d had %d\n, vlc.table_size, 
static_size);
+
+for (i = 0; i  vlc.table_size; i++) {
+int code = vlc.table[i][0];
+int len  = vlc.table[i][1];
 int level, run;
 
 if (len == 0) { // illegal code
@@ -110,6 +110,7 @@ static av_cold void init_2d_vlc_rl(RLTable *rl, const VLC 
*vlc)
 rl-rl_vlc[0][i].level = level;
 rl-rl_vlc[0][i].run   = run;
 }
+ff_free_vlc(vlc);
 }
 
 av_cold void ff_mpeg12_common_init(MpegEncContext *s)
diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index 748dbc8..94e000f 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -1618,9 +1618,14 @@ av_cold void ff_init_rl(RLTable *rl,
 }
 }
 
-av_cold void ff_init_vlc_rl(RLTable *rl, const VLC *vlc)
+av_cold void ff_init_vlc_rl(RLTable *rl, unsigned static_size)
 {
 int i, q;
+VLC vlc;
+init_vlc(vlc, 9, rl-n + 1, rl-table_vlc[0][1], 4, 2, 
rl-table_vlc[0][0], 4, 2, 0);
+av_assert0(vlc.table_size = static_size);
+if (vlc.table_size != static_size)
+av_log(NULL, AV_LOG_ERROR, needed %d had %d\n, vlc.table_size, 
static_size);
 
 for (q = 0; q  32; q++) {
 int qmul = q * 2;
@@ -1630,9 +1635,9 @@ av_cold void ff_init_vlc_rl(RLTable *rl, const VLC *vlc)
 qmul = 1;
 qadd = 0;
 }
-for (i = 0; i  vlc-table_size; i++) {
-int code = vlc-table[i][0];
-int len  = vlc-table[i][1];
+for (i = 0; i  vlc.table_size; i++) {
+int code = vlc.table[i][0];
+int len  = vlc.table[i][1];
 int level, run;
 
 if (len == 0) { // illegal code
@@ -1656,6 +1661,7 @@ av_cold void ff_init_vlc_rl(RLTable *rl, const VLC *vlc)
 rl-rl_vlc[q][i].run   = run;
 }
 }
+ff_free_vlc(vlc);
 }
 
 static void release_unused_pictures(MpegEncContext *s)
diff --git a/libavcodec/rl.h b/libavcodec/rl.h
index 3cef366..2897ec5 100644
--- a/libavcodec/rl.h
+++ b/libavcodec/rl.h
@@ -53,22 +53,18 @@ typedef struct RLTable {
  * the level and run tables, if this is NULL av_malloc() 
will be used
  */
 void ff_init_rl(RLTable *rl, uint8_t static_store[2][2*MAX_RUN + MAX_LEVEL + 
3]);
-void ff_init_vlc_rl(RLTable *rl, const VLC *vlc);
+void ff_init_vlc_rl(RLTable *rl, unsigned static_size);
 
 #define INIT_VLC_RL(rl, static_size)\
 {\
 int q;\
 static RL_VLC_ELEM rl_vlc_table[32][static_size];\
-VLC tmp_vlc;\
-INIT_VLC_STATIC(tmp_vlc, 9, rl.n + 1,\
- rl.table_vlc[0][1], 4, 2,\
- rl.table_vlc[0][0], 4, 2, static_size);\
 \
 if(!rl.rl_vlc[0]){\
 for(q=0; q32; q++)\
 rl.rl_vlc[q]= rl_vlc_table[q];\
 \
-ff_init_vlc_rl(rl, tmp_vlc);\
+ff_init_vlc_rl(rl, static_size);\
 }\
 }
 
-- 
2.1.0

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


Re: [FFmpeg-devel] [PATCH] rl.h: Allocate temporary VLC tables instead of having them static.

2014-08-31 Thread Reimar Döffinger
On Sun, Aug 31, 2014 at 08:27:17PM +0200, Reimar Döffinger wrote:
 Signed-off-by: Reimar Döffinger reimar.doeffin...@gmx.de

This was intended to come out under rl.h: remove deprecated and now unused vlc 
member.,
as that one needs to be applied first.
I can merge them though if desired.
I by accident typed -1 when I had wanted to type --help...
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel