]> git.sesse.net Git - ffmpeg/commitdiff
* first shot for the new avcodec API
authorZdenek Kabelac <kabi@informatics.muni.cz>
Tue, 14 May 2002 14:17:11 +0000 (14:17 +0000)
committerZdenek Kabelac <kabi@informatics.muni.cz>
Tue, 14 May 2002 14:17:11 +0000 (14:17 +0000)
  - comments, critics, improvements on the ffmpeg list are welcomed

Originally committed as revision 494 to svn://svn.ffmpeg.org/ffmpeg/trunk

libavcodec/avcodec.c [new file with mode: 0644]
libavcodec/avcodec.h

diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c
new file mode 100644 (file)
index 0000000..e0e0496
--- /dev/null
@@ -0,0 +1,150 @@
+#include "errno.h"
+#include "avcodec.h"
+
+#ifndef MKTAG
+#define MKTAG(a,b,c,d) (a | (b << 8) | (c << 16) | (d << 24))
+#endif
+
+// private structure used to hide all internal memory allocations
+// and structures used for de/encoding - end user should
+// never see any complicated structure
+typedef struct
+{
+    AVCodec* avcodec;
+    AVCodecContext avcontext;
+} private_handle_t;
+
+static AVCodec* avcodec_find_by_fcc(uint32_t fcc)
+{
+    // translation table
+    static const struct fcc_to_avcodecid {
+       enum CodecID codec;
+       uint32_t list[4]; // maybe we could map more fcc to same codec
+    } lc[] = {
+       { CODEC_ID_H263, { MKTAG('U', '2', '6', '3'), 0 } },
+       { CODEC_ID_H263I, { MKTAG('I', '2', '6', '3'), 0 } },
+       { CODEC_ID_MSMPEG4, { MKTAG('D', 'I', 'V', '3'), 0 } },
+       { CODEC_ID_MPEG4, { MKTAG('D', 'I', 'V', 'X'),  MKTAG('D', 'X', '5', '0'), 0 } },
+       { CODEC_ID_MSMPEG4V2, { MKTAG('M', 'P', '4', '2'), 0 } },
+       { CODEC_ID_MJPEG, { MKTAG('M', 'J', 'P', 'G'), 0 } },
+       { CODEC_ID_MPEG1VIDEO, { MKTAG('P', 'I', 'M', '1'), 0 } },
+       { CODEC_ID_AC3, { 0x2000, 0 } },
+       { CODEC_ID_MP2, { 0x50, 0x55, 0 } },
+
+       { CODEC_ID_NONE, {0}}
+    };
+    const struct fcc_to_avcodecid* c;
+
+    for (c = lc; c->codec != CODEC_ID_NONE; c++)
+    {
+       int i = 0;
+       while (c->list[i] != 0)
+           if (c->list[i++] == fcc)
+               return avcodec_find_decoder(c->codec);
+    }
+
+    return NULL;
+}
+
+static private_handle_t* create_handle()
+{
+    private_handle_t* t = malloc(sizeof(private_handle_t));
+    if (!t)
+       return NULL;
+
+    // register and fill
+    avcodec_init();
+    avcodec_register_all();
+    return t;
+}
+
+static void destroy_handle(private_handle_t* handle)
+{
+    if (handle)
+    {
+       if (handle->avcodec)
+       {
+           avcodec_close(&handle->avcontext);
+       }
+       free(handle);
+
+        // count referencies
+    }
+}
+
+int avcodec(void* handle, avc_cmd_t cmd, void* pin, void* pout)
+{
+    AVCodecContext* ctx = handle;
+    switch (cmd)
+    {
+    case AVC_OPEN_BY_NAME:
+       {
+            // pin  char* codec name
+           private_handle_t* handle = create_handle();
+           (private_handle_t**)pout = handle;
+           if (!handle)
+               return -ENOMEM;
+           if (!handle->avcodec)
+           {
+               destroy_handle(handle);
+               (private_handle_t**)pout = NULL;
+               return -1;// better error
+           }
+            return 0;
+       }
+    case AVC_OPEN_BY_CODEC_ID:
+       {
+            // pin  uint32_t codec fourcc
+           private_handle_t* handle = create_handle();
+           (private_handle_t**)pout = handle;
+           if (!handle)
+               return -ENOMEM;
+
+           if (!handle->avcodec)
+           {
+               destroy_handle(handle);
+               (private_handle_t**)pout = NULL;
+               return -1;// better error
+           }
+            return 0;
+       }
+    case AVC_OPEN_BY_FOURCC:
+       {
+            // pin  uint32_t codec fourcc
+           private_handle_t* handle = create_handle();
+           (private_handle_t**)pout = handle;
+           if (!handle)
+               return -ENOMEM;
+           handle->avcodec = avcodec_find_by_fcc((uint32_t) pin);
+           if (!handle->avcodec)
+           {
+               destroy_handle(handle);
+               (private_handle_t**)pout = NULL;
+               return -1;// better error
+           }
+            return 0;
+       }
+    case AVC_CLOSE:
+       // uninit part
+       // eventually close all allocated space if this was last
+       // instance
+       destroy_handle(handle);
+       break;
+
+    case AVC_FLUSH:
+       break;
+
+    case AVC_DECODE:
+       break;
+
+    case AVC_ENCODE:
+       break;
+
+    case AVC_GET_VERSION:
+        (int*) pout = 500;
+    default:
+       return -1;
+
+    }
+    return 0;
+}
index 3bd0b8a9bb71daa8df0ee0a9f2ed5beacc2938f0..a56f9f130b63049bfa5c3a85ea9b32604ecc886a 100644 (file)
@@ -426,4 +426,81 @@ void avcodec_flush_buffers(AVCodecContext *avctx);
 extern int quant_store[MBR+1][MBC+1]; // [Review]
 #endif
 
+
+/**
+ * Interface for 0.5.0 version
+ *
+ * do not even think about it's usage for this moment
+ */
+
+typedef struct {
+    // compressed size used from given memory buffer
+    int size;
+    /// I/P/B frame type
+    int frame_type;
+} avc_enc_result_t;
+
+/**
+ * Commands
+ * order can't be changed - once it was defined
+ */
+typedef enum {
+    // general commands
+    AVC_OPEN_BY_NAME = 0xACA000,
+    AVC_OPEN_BY_CODEC_ID,
+    AVC_OPEN_BY_FOURCC,
+    AVC_CLOSE,
+
+    AVC_FLUSH,
+    // pin - struct { uint8_t* src, uint_t src_size }
+    // pout - struct { AVPicture* img, consumed_bytes,
+    AVC_DECODE,
+    // pin - struct { AVPicture* img, uint8_t* dest, uint_t dest_size }
+    // pout - uint_t used_from_dest_size
+    AVC_ENCODE, 
+
+    // query/get video commands
+    AVC_GET_VERSION = 0xACB000,
+    AVC_GET_WIDTH,
+    AVC_GET_HEIGHT,
+    AVC_GET_DELAY,
+    AVC_GET_QUANT_TABLE,
+    // ...
+
+    // query/get audio commands
+    AVC_GET_FRAME_SIZE = 0xABC000,
+
+    // maybe define some simple structure which
+    // might be passed to the user - but they can't
+    // contain any codec specific parts and these
+    // calls are usualy necessary only few times
+
+    // set video commands
+    AVC_SET_WIDTH = 0xACD000,
+    AVC_SET_HEIGHT,
+
+    // set video encoding commands
+    AVC_SET_FRAME_RATE = 0xACD800,
+    AVC_SET_QUALITY,
+    AVC_SET_HURRY_UP,
+
+    // set audio commands
+    AVC_SET_SAMPLE_RATE = 0xACE000,
+    AVC_SET_CHANNELS,
+
+} avc_cmd_t;
+
+/**
+ * \param handle  allocated private structure by libavcodec
+ *                for initialization pass NULL - will be returned pout
+ *                user is supposed to know nothing about its structure
+ * \param cmd     type of operation to be performed
+ * \param pint    input parameter
+ * \param pout    output parameter
+ *
+ * \returns  command status - eventually for query command it might return
+ * integer resulting value
+ */
+int avcodec(void* handle, avc_cmd_t cmd, void* pin, void* pout);
+
 #endif /* AVCODEC_H */