]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/dtsdec.c
Move the ratecontrol related code from mpegvideo.h to a separate header file.
[ffmpeg] / libavcodec / dtsdec.c
index 2bc88d078b3dbe9fd0f7668b10dcfe0614fcb083..dd3268217ed20437ab0190e868444d73407b8c00 100644 (file)
@@ -8,12 +8,12 @@
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
  * (at your option) any later version.
- *  
+ *
  * This library 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 General Public License for more details.
- *  
+ *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
 #include <stdlib.h>
 #include <string.h>
+
+#ifdef HAVE_MALLOC_H
 #include <malloc.h>
+#endif
 
-#define INBUF_SIZE 4096
-#define BUFFER_SIZE 4096
+#define BUFFER_SIZE 18726
 #define HEADER_SIZE 14
 
 #ifdef LIBDTS_FIXED
@@ -191,7 +193,7 @@ channels_multi (int flags)
 {
   if (flags & DTS_LFE)
     return 6;
-  else if (flags & 1)  /* center channel */
+  else if (flags & 1)   /* center channel */
     return 5;
   else if ((flags & DTS_CHANNEL_MASK) == DTS_2F2R)
     return 4;
@@ -205,8 +207,6 @@ dts_decode_frame (AVCodecContext *avctx, void *data, int *data_size,
 {
   uint8_t * start = buff;
   uint8_t * end = buff + buff_size;
-  *data_size = 0;
-
   static uint8_t buf[BUFFER_SIZE];
   static uint8_t * bufptr = buf;
   static uint8_t * bufpos = buf + HEADER_SIZE;
@@ -218,6 +218,8 @@ dts_decode_frame (AVCodecContext *avctx, void *data, int *data_size,
   int len;
   dts_state_t *state = avctx->priv_data;
 
+  *data_size = 0;
+
   while (1)
     {
       len = end - start;
@@ -228,9 +230,11 @@ dts_decode_frame (AVCodecContext *avctx, void *data, int *data_size,
       memcpy (bufptr, start, len);
       bufptr += len;
       start += len;
-      if (bufptr == bufpos)
-        {
-          if (bufpos == buf + HEADER_SIZE)
+      if (bufptr != bufpos)
+          return start - buff;
+      if (bufpos != buf + HEADER_SIZE)
+          break;
+
             {
               int length;
 
@@ -245,7 +249,8 @@ dts_decode_frame (AVCodecContext *avctx, void *data, int *data_size,
                 }
               bufpos = buf + length;
             }
-          else
+    }
+
             {
               level_t level;
               sample_t bias;
@@ -258,6 +263,9 @@ dts_decode_frame (AVCodecContext *avctx, void *data, int *data_size,
               flags |= DTS_ADJUST_LEVEL;
               if (dts_frame (state, buf, &flags, &level, bias))
                 goto error;
+              avctx->sample_rate = sample_rate;
+              avctx->channels = channels_multi (flags);
+              avctx->bit_rate = bit_rate;
               for (i = 0; i < dts_blocks_num (state); i++)
                 {
                   if (dts_block (state))
@@ -274,16 +282,14 @@ dts_decode_frame (AVCodecContext *avctx, void *data, int *data_size,
                 }
               bufptr = buf;
               bufpos = buf + HEADER_SIZE;
-              continue;
+              return start-buff;
             error:
               av_log (NULL, AV_LOG_ERROR, "error\n");
               bufptr = buf;
               bufpos = buf + HEADER_SIZE;
             }
-        }
-    }
 
-  return buff_size;
+  return start-buff;
 }
 
 static int
@@ -291,7 +297,7 @@ dts_decode_init (AVCodecContext *avctx)
 {
   avctx->priv_data = dts_init (0);
   if (avctx->priv_data == NULL)
-    return 1;
+    return -1;
 
   return 0;
 }
@@ -303,7 +309,7 @@ dts_decode_end (AVCodecContext *s)
 }
 
 AVCodec dts_decoder = {
-  "dts", 
+  "dts",
   CODEC_TYPE_AUDIO,
   CODEC_ID_DTS,
   sizeof (dts_state_t *),