[MPlayer-cvslog] r27301 - in trunk/libmpdemux: demux_asf.c demux_real.c demux_viv.c demuxer.h video.c

Reimar Döffinger Reimar.Doeffinger at stud.uni-karlsruhe.de
Wed Jul 16 21:00:09 CEST 2008


Hello,
On Wed, Jul 16, 2008 at 08:05:43PM +0300, Uoti Urpala wrote:
> On Wed, 2008-07-16 at 18:18 +0200, reimar wrote:
> > --- trunk/libmpdemux/demuxer.h	(original)
> > +++ trunk/libmpdemux/demuxer.h	Wed Jul 16 18:18:25 2008
> > @@ -93,6 +93,12 @@
> >  #define SEEK_ABSOLUTE (1 << 0)
> >  #define SEEK_FACTOR   (1 << 1)
> >  
> > +#ifdef USE_LIBAVCODEC
> > +#include "libavcodec/avcodec.h"
> 
> Diego thought about doing something like this a year ago, but it wasn't
> done because demuxer.h is included in so many files.
> 
> http://lists.mplayerhq.hu/pipermail/mplayer-dev-eng/2007-July/052886.html
> 
> $ find . -name '*.d' -print0 | xargs -0 grep demuxer.h | wc -l
> 116
> 
> IMO the same reasons still apply. A 3k line header shouldn't be included
> in that many files because a couple of them need a definition from it.

There are far more files in libav* that all include it, but I think I
found a solution that is better in all aspects.
Ok to apply?

Greetings,
Reimar Döffinger
-------------- next part --------------
Index: demux_asf.c
===================================================================
--- demux_asf.c	(revision 27305)
+++ demux_asf.c	(working copy)
@@ -54,9 +54,9 @@
   unsigned char *dst;
   unsigned char *s2=*src;
   unsigned i=0,x,y;
-  if (len > UINT_MAX - FF_INPUT_BUFFER_PADDING_SIZE)
+  if (len > UINT_MAX - MP_INPUT_BUFFER_PADDING_SIZE)
 	return;
-  dst = malloc(len + FF_INPUT_BUFFER_PADDING_SIZE);
+  dst = malloc(len + MP_INPUT_BUFFER_PADDING_SIZE);
   while(len>=asf->scrambling_h*asf->scrambling_w*asf->scrambling_b+i){
 //    mp_msg(MSGT_DEMUX,MSGL_DBG4,"descrambling! (w=%d  b=%d)\n",w,asf_scrambling_b);
 	//i+=asf_scrambling_h*asf_scrambling_w;
@@ -86,9 +86,9 @@
 static void demux_asf_append_to_packet(demux_packet_t* dp,unsigned char *data,int len,int offs)
 {
   if(dp->len!=offs && offs!=-1) mp_msg(MSGT_DEMUX,MSGL_V,"warning! fragment.len=%d BUT next fragment offset=%d  \n",dp->len,offs);
-  dp->buffer=realloc(dp->buffer,dp->len+len+FF_INPUT_BUFFER_PADDING_SIZE);
+  dp->buffer=realloc(dp->buffer,dp->len+len+MP_INPUT_BUFFER_PADDING_SIZE);
   fast_memcpy(dp->buffer+dp->len,data,len);
-  memset(dp->buffer+dp->len+len, 0, FF_INPUT_BUFFER_PADDING_SIZE);
+  memset(dp->buffer+dp->len+len, 0, MP_INPUT_BUFFER_PADDING_SIZE);
   mp_dbg(MSGT_DEMUX,MSGL_DBG4,"data appended! %d+%d\n",dp->len,len);
   dp->len+=len;
 }
Index: demux_real.c
===================================================================
--- demux_real.c	(revision 27301)
+++ demux_real.c	(working copy)
@@ -934,8 +934,8 @@
 			    // increase buffer size, this should not happen!
 			    mp_msg(MSGT_DEMUX,MSGL_WARN, "chunktab buffer too small!!!!!\n");
 			    dp->len=dp_hdr->chunktab+8*(4+dp_hdr->chunks);
-			    dp->buffer=realloc(dp->buffer,dp->len+FF_INPUT_BUFFER_PADDING_SIZE);
-			    memset(dp->buffer + dp->len, 0, FF_INPUT_BUFFER_PADDING_SIZE);
+			    dp->buffer=realloc(dp->buffer,dp->len+MP_INPUT_BUFFER_PADDING_SIZE);
+			    memset(dp->buffer + dp->len, 0, MP_INPUT_BUFFER_PADDING_SIZE);
 			    // re-calc pointers:
 			    dp_hdr=(dp_hdr_t*)dp->buffer;
 			    dp_data=dp->buffer+sizeof(dp_hdr_t);
Index: demux_viv.c
===================================================================
--- demux_viv.c	(revision 27301)
+++ demux_viv.c	(working copy)
@@ -378,10 +378,10 @@
       } else {
         // append data to it!
         demux_packet_t* dp=ds->asf_packet;
-        if(dp->len + len + FF_INPUT_BUFFER_PADDING_SIZE < 0)
+        if(dp->len + len + MP_INPUT_BUFFER_PADDING_SIZE < 0)
 	    return 0;
-        dp->buffer=realloc(dp->buffer,dp->len+len+FF_INPUT_BUFFER_PADDING_SIZE);
-        memset(dp->buffer+dp->len+len, 0, FF_INPUT_BUFFER_PADDING_SIZE);
+        dp->buffer=realloc(dp->buffer,dp->len+len+MP_INPUT_BUFFER_PADDING_SIZE);
+        memset(dp->buffer+dp->len+len, 0, MP_INPUT_BUFFER_PADDING_SIZE);
         //memcpy(dp->buffer+dp->len,data,len);
 	stream_read(demux->stream,dp->buffer+dp->len,len);
         mp_dbg(MSGT_DEMUX,MSGL_DBG4,"data appended! %d+%d\n",dp->len,len);
Index: demuxer.h
===================================================================
--- demuxer.h	(revision 27301)
+++ demuxer.h	(working copy)
@@ -93,11 +93,7 @@
 #define SEEK_ABSOLUTE (1 << 0)
 #define SEEK_FACTOR   (1 << 1)
 
-#ifdef USE_LIBAVCODEC
-#include "libavcodec/avcodec.h"
-#else
-#define FF_INPUT_BUFFER_PADDING_SIZE 8
-#endif
+#define MP_INPUT_BUFFER_PADDING_SIZE 8
 
 // Holds one packet/frame/whatever
 typedef struct demux_packet_st {
@@ -249,7 +245,7 @@
   dp->refcount=1;
   dp->master=NULL;
   dp->buffer=NULL;
-  if (len > 0 && (dp->buffer = (unsigned char *)malloc(len + FF_INPUT_BUFFER_PADDING_SIZE)))
+  if (len > 0 && (dp->buffer = (unsigned char *)malloc(len + MP_INPUT_BUFFER_PADDING_SIZE)))
     memset(dp->buffer + len, 0, 8);
   else
     dp->len = 0;
Index: demuxer.c
===================================================================
--- demuxer.c	(revision 27288)
+++ demuxer.c	(working copy)
@@ -27,6 +27,13 @@
 #include "libass/ass_mp.h"
 #endif
 
+#ifdef USE_LIBAVCODEC
+#include "libavcodec/avcodec.h"
+#if MP_INPUT_BUFFER_PADDING_SIZE < FF_INPUT_BUFFER_PADDING_SIZE
+#error MP_INPUT_BUFFER_PADDING_SIZE is too small!
+#endif
+#endif
+
 extern void resync_video_stream(sh_video_t *sh_video);
 extern void resync_audio_stream(sh_audio_t *sh_audio);
 
Index: video.c
===================================================================
--- video.c	(revision 27301)
+++ video.c	(working copy)
@@ -111,8 +111,8 @@
    }
    mp_msg(MSGT_DECVIDEO,MSGL_V,"OK!\n");
    if(!videobuffer) {
-     videobuffer=(char*)memalign(8,VIDEOBUFFER_SIZE + FF_INPUT_BUFFER_PADDING_SIZE);
-     if (videobuffer) memset(videobuffer+VIDEOBUFFER_SIZE, 0, FF_INPUT_BUFFER_PADDING_SIZE);
+     videobuffer=(char*)memalign(8,VIDEOBUFFER_SIZE + MP_INPUT_BUFFER_PADDING_SIZE);
+     if (videobuffer) memset(videobuffer+VIDEOBUFFER_SIZE, 0, MP_INPUT_BUFFER_PADDING_SIZE);
      else {
        mp_msg(MSGT_DECVIDEO,MSGL_ERR,MSGTR_ShMemAllocFail);
        return 0;
@@ -204,8 +204,8 @@
    }
    mp_msg(MSGT_DECVIDEO,MSGL_V,"OK!\n");
    if(!videobuffer) {
-     videobuffer=(char*)memalign(8,VIDEOBUFFER_SIZE + FF_INPUT_BUFFER_PADDING_SIZE);
-     if (videobuffer) memset(videobuffer+VIDEOBUFFER_SIZE, 0, FF_INPUT_BUFFER_PADDING_SIZE);
+     videobuffer=(char*)memalign(8,VIDEOBUFFER_SIZE + MP_INPUT_BUFFER_PADDING_SIZE);
+     if (videobuffer) memset(videobuffer+VIDEOBUFFER_SIZE, 0, MP_INPUT_BUFFER_PADDING_SIZE);
      else {
        mp_msg(MSGT_DECVIDEO,MSGL_ERR,MSGTR_ShMemAllocFail);
        return 0;
@@ -267,8 +267,8 @@
    mp_msg(MSGT_DECVIDEO,MSGL_V,"OK!\n");
    // ========= Read & process sequence header & extension ============
    if(!videobuffer) {
-     videobuffer=(char*)memalign(8,VIDEOBUFFER_SIZE + FF_INPUT_BUFFER_PADDING_SIZE);
-     if (videobuffer) memset(videobuffer+VIDEOBUFFER_SIZE, 0, FF_INPUT_BUFFER_PADDING_SIZE);
+     videobuffer=(char*)memalign(8,VIDEOBUFFER_SIZE + MP_INPUT_BUFFER_PADDING_SIZE);
+     if (videobuffer) memset(videobuffer+VIDEOBUFFER_SIZE, 0, MP_INPUT_BUFFER_PADDING_SIZE);
      else {
        mp_msg(MSGT_DECVIDEO,MSGL_ERR,MSGTR_ShMemAllocFail);
        return 0;
@@ -335,8 +335,8 @@
    }
    mp_msg(MSGT_DECVIDEO,MSGL_INFO,"found\n");
    if(!videobuffer) {
-     videobuffer=(char*)memalign(8,VIDEOBUFFER_SIZE + FF_INPUT_BUFFER_PADDING_SIZE);
-     if (videobuffer) memset(videobuffer+VIDEOBUFFER_SIZE, 0, FF_INPUT_BUFFER_PADDING_SIZE);
+     videobuffer=(char*)memalign(8,VIDEOBUFFER_SIZE + MP_INPUT_BUFFER_PADDING_SIZE);
+     if (videobuffer) memset(videobuffer+VIDEOBUFFER_SIZE, 0, MP_INPUT_BUFFER_PADDING_SIZE);
      else {
        mp_msg(MSGT_DECVIDEO,MSGL_ERR,MSGTR_ShMemAllocFail);
        return 0;


More information about the MPlayer-cvslog mailing list