Commit 9cef0669 authored by Diego Biurrun's avatar Diego Biurrun

Move code shared between libdirac and libschroedinger to libschroedinger.

This also involves making some function static and changing the name
prefixes of some functions and structures.
parent 8134fafe
......@@ -601,11 +601,9 @@ OBJS-$(CONFIG_LIBOPENCORE_AMRNB_ENCODER) += libopencore-amr.o
OBJS-$(CONFIG_LIBOPENCORE_AMRWB_DECODER) += libopencore-amr.o
OBJS-$(CONFIG_LIBOPENJPEG_DECODER) += libopenjpeg.o
OBJS-$(CONFIG_LIBSCHROEDINGER_DECODER) += libschroedingerdec.o \
libschroedinger.o \
libdirac_libschro.o
libschroedinger.o
OBJS-$(CONFIG_LIBSCHROEDINGER_ENCODER) += libschroedingerenc.o \
libschroedinger.o \
libdirac_libschro.o
libschroedinger.o
OBJS-$(CONFIG_LIBSPEEX_DECODER) += libspeexdec.o
OBJS-$(CONFIG_LIBSPEEX_ENCODER) += libspeexenc.o audio_frame_queue.o
OBJS-$(CONFIG_LIBTHEORA_ENCODER) += libtheoraenc.o
......
/*
* Copyright (c) 2008 BBC, Anuradha Suraparaju <asuraparaju at gmail dot com >
*
* This file is part of Libav.
*
* Libav 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.
*
* Libav 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 Libav; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file
* functions common to libdirac and libschroedinger
*/
#include "libdirac_libschro.h"
static const DiracSchroVideoFormatInfo ff_dirac_schro_video_format_info[] = {
{ 640, 480, 24000, 1001},
{ 176, 120, 15000, 1001},
{ 176, 144, 25, 2 },
{ 352, 240, 15000, 1001},
{ 352, 288, 25, 2 },
{ 704, 480, 15000, 1001},
{ 704, 576, 25, 2 },
{ 720, 480, 30000, 1001},
{ 720, 576, 25, 1 },
{ 1280, 720, 60000, 1001},
{ 1280, 720, 50, 1 },
{ 1920, 1080, 30000, 1001},
{ 1920, 1080, 25, 1 },
{ 1920, 1080, 60000, 1001},
{ 1920, 1080, 50, 1 },
{ 2048, 1080, 24, 1 },
{ 4096, 2160, 24, 1 },
};
unsigned int ff_dirac_schro_get_video_format_idx(AVCodecContext *avccontext)
{
unsigned int ret_idx = 0;
unsigned int idx;
unsigned int num_formats = sizeof(ff_dirac_schro_video_format_info) /
sizeof(ff_dirac_schro_video_format_info[0]);
for (idx = 1; idx < num_formats; ++idx) {
const DiracSchroVideoFormatInfo *vf = &ff_dirac_schro_video_format_info[idx];
if (avccontext->width == vf->width &&
avccontext->height == vf->height) {
ret_idx = idx;
if (avccontext->time_base.den == vf->frame_rate_num &&
avccontext->time_base.num == vf->frame_rate_denom)
return idx;
}
}
return ret_idx;
}
void ff_dirac_schro_queue_init(DiracSchroQueue *queue)
{
queue->p_head = queue->p_tail = NULL;
queue->size = 0;
}
void ff_dirac_schro_queue_free(DiracSchroQueue *queue,
void (*free_func)(void *))
{
while (queue->p_head)
free_func(ff_dirac_schro_queue_pop(queue));
}
int ff_dirac_schro_queue_push_back(DiracSchroQueue *queue, void *p_data)
{
DiracSchroQueueElement *p_new = av_mallocz(sizeof(DiracSchroQueueElement));
if (!p_new)
return -1;
p_new->data = p_data;
if (!queue->p_head)
queue->p_head = p_new;
else
queue->p_tail->next = p_new;
queue->p_tail = p_new;
++queue->size;
return 0;
}
void *ff_dirac_schro_queue_pop(DiracSchroQueue *queue)
{
DiracSchroQueueElement *top = queue->p_head;
if (top) {
void *data = top->data;
queue->p_head = queue->p_head->next;
--queue->size;
av_freep(&top);
return data;
}
return NULL;
}
/*
* Copyright (c) 2008 BBC, Anuradha Suraparaju <asuraparaju at gmail dot com >
*
* This file is part of Libav.
*
* Libav 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.
*
* Libav 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 Libav; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file
* data structures common to libdirac and libschroedinger
*/
#ifndef AVCODEC_LIBDIRAC_LIBSCHRO_H
#define AVCODEC_LIBDIRAC_LIBSCHRO_H
#include "avcodec.h"
typedef struct {
uint16_t width;
uint16_t height;
uint16_t frame_rate_num;
uint16_t frame_rate_denom;
} DiracSchroVideoFormatInfo;
/**
* Returns the index into the Dirac Schro common video format info table
*/
unsigned int ff_dirac_schro_get_video_format_idx(AVCodecContext *avccontext);
/**
* contains a single encoded frame returned from Dirac or Schroedinger
*/
typedef struct DiracSchroEncodedFrame {
/** encoded frame data */
uint8_t *p_encbuf;
/** encoded frame size */
uint32_t size;
/** encoded frame number. Will be used as pts */
uint32_t frame_num;
/** key frame flag. 1 : is key frame , 0 : in not key frame */
uint16_t key_frame;
} DiracSchroEncodedFrame;
/**
* queue element
*/
typedef struct DiracSchroQueueElement {
/** Data to be stored in queue*/
void *data;
/** Pointer to next element queue */
struct DiracSchroQueueElement *next;
} DiracSchroQueueElement;
/**
* A simple queue implementation used in libdirac and libschroedinger
*/
typedef struct DiracSchroQueue {
/** Pointer to head of queue */
DiracSchroQueueElement *p_head;
/** Pointer to tail of queue */
DiracSchroQueueElement *p_tail;
/** Queue size*/
int size;
} DiracSchroQueue;
/**
* Initialise the queue
*/
void ff_dirac_schro_queue_init(DiracSchroQueue *queue);
/**
* Add an element to the end of the queue
*/
int ff_dirac_schro_queue_push_back(DiracSchroQueue *queue, void *p_data);
/**
* Return the first element in the queue
*/
void *ff_dirac_schro_queue_pop(DiracSchroQueue *queue);
/**
* Free the queue resources. free_func is a function supplied by the caller to
* free any resources allocated by the caller. The data field of the queue
* element is passed to it.
*/
void ff_dirac_schro_queue_free(DiracSchroQueue *queue,
void (*free_func)(void *));
#endif /* AVCODEC_LIBDIRAC_LIBSCHRO_H */
......@@ -23,12 +23,97 @@
* function definitions common to libschroedinger decoder and encoder
*/
#include "libdirac_libschro.h"
#include "libschroedinger.h"
static const SchroVideoFormatInfo ff_schro_video_format_info[] = {
{ 640, 480, 24000, 1001},
{ 176, 120, 15000, 1001},
{ 176, 144, 25, 2 },
{ 352, 240, 15000, 1001},
{ 352, 288, 25, 2 },
{ 704, 480, 15000, 1001},
{ 704, 576, 25, 2 },
{ 720, 480, 30000, 1001},
{ 720, 576, 25, 1 },
{ 1280, 720, 60000, 1001},
{ 1280, 720, 50, 1 },
{ 1920, 1080, 30000, 1001},
{ 1920, 1080, 25, 1 },
{ 1920, 1080, 60000, 1001},
{ 1920, 1080, 50, 1 },
{ 2048, 1080, 24, 1 },
{ 4096, 2160, 24, 1 },
};
static unsigned int get_video_format_idx(AVCodecContext *avccontext)
{
unsigned int ret_idx = 0;
unsigned int idx;
unsigned int num_formats = sizeof(ff_schro_video_format_info) /
sizeof(ff_schro_video_format_info[0]);
for (idx = 1; idx < num_formats; ++idx) {
const SchroVideoFormatInfo *vf = &ff_schro_video_format_info[idx];
if (avccontext->width == vf->width &&
avccontext->height == vf->height) {
ret_idx = idx;
if (avccontext->time_base.den == vf->frame_rate_num &&
avccontext->time_base.num == vf->frame_rate_denom)
return idx;
}
}
return ret_idx;
}
void ff_schro_queue_init(FFSchroQueue *queue)
{
queue->p_head = queue->p_tail = NULL;
queue->size = 0;
}
void ff_schro_queue_free(FFSchroQueue *queue, void (*free_func)(void *))
{
while (queue->p_head)
free_func(ff_schro_queue_pop(queue));
}
int ff_schro_queue_push_back(FFSchroQueue *queue, void *p_data)
{
FFSchroQueueElement *p_new = av_mallocz(sizeof(FFSchroQueueElement));
if (!p_new)
return -1;
p_new->data = p_data;
if (!queue->p_head)
queue->p_head = p_new;
else
queue->p_tail->next = p_new;
queue->p_tail = p_new;
++queue->size;
return 0;
}
void *ff_schro_queue_pop(FFSchroQueue *queue)
{
FFSchroQueueElement *top = queue->p_head;
if (top) {
void *data = top->data;
queue->p_head = queue->p_head->next;
--queue->size;
av_freep(&top);
return data;
}
return NULL;
}
/**
* Schroedinger video preset table. Ensure that this tables matches up correctly
* with the ff_dirac_schro_video_format_info table in libdirac_libschro.c.
* with the ff_schro_video_format_info table.
*/
static const SchroVideoFormatEnum ff_schro_video_formats[]={
SCHRO_VIDEO_FORMAT_CUSTOM ,
......@@ -55,7 +140,7 @@ SchroVideoFormatEnum ff_get_schro_video_format_preset(AVCodecContext *avccontext
unsigned int num_formats = sizeof(ff_schro_video_formats) /
sizeof(ff_schro_video_formats[0]);
unsigned int idx = ff_dirac_schro_get_video_format_idx (avccontext);
unsigned int idx = get_video_format_idx(avccontext);
return (idx < num_formats) ? ff_schro_video_formats[idx] :
SCHRO_VIDEO_FORMAT_CUSTOM;
......
......@@ -28,8 +28,78 @@
#include <schroedinger/schrobitstream.h>
#include <schroedinger/schroframe.h>
#include "avcodec.h"
typedef struct {
uint16_t width;
uint16_t height;
uint16_t frame_rate_num;
uint16_t frame_rate_denom;
} SchroVideoFormatInfo;
/**
* contains a single encoded frame returned from Dirac or Schroedinger
*/
typedef struct FFSchroEncodedFrame {
/** encoded frame data */
uint8_t *p_encbuf;
/** encoded frame size */
uint32_t size;
/** encoded frame number. Will be used as pts */
uint32_t frame_num;
/** key frame flag. 1 : is key frame , 0 : in not key frame */
uint16_t key_frame;
} FFSchroEncodedFrame;
/**
* queue element
*/
typedef struct FFSchroQueueElement {
/** Data to be stored in queue*/
void *data;
/** Pointer to next element queue */
struct FFSchroQueueElement *next;
} FFSchroQueueElement;
/**
* A simple queue implementation used in libschroedinger
*/
typedef struct FFSchroQueue {
/** Pointer to head of queue */
FFSchroQueueElement *p_head;
/** Pointer to tail of queue */
FFSchroQueueElement *p_tail;
/** Queue size*/
int size;
} FFSchroQueue;
/**
* Initialise the queue
*/
void ff_schro_queue_init(FFSchroQueue *queue);
/**
* Add an element to the end of the queue
*/
int ff_schro_queue_push_back(FFSchroQueue *queue, void *p_data);
/**
* Return the first element in the queue
*/
void *ff_schro_queue_pop(FFSchroQueue *queue);
/**
* Free the queue resources. free_func is a function supplied by the caller to
* free any resources allocated by the caller. The data field of the queue
* element is passed to it.
*/
void ff_schro_queue_free(FFSchroQueue *queue, void (*free_func)(void *));
static const struct {
enum PixelFormat ff_pix_fmt;
SchroChromaFormat schro_pix_fmt;
......
......@@ -29,7 +29,6 @@
#include "libavutil/imgutils.h"
#include "avcodec.h"
#include "libdirac_libschro.h"
#include "libschroedinger.h"
#undef NDEBUG
......@@ -52,7 +51,7 @@ typedef struct SchroDecoderParams {
SchroDecoder* decoder;
/** queue storing decoded frames */
DiracSchroQueue dec_frame_queue;
FFSchroQueue dec_frame_queue;
/** end of sequence signalled */
int eos_signalled;
......@@ -155,7 +154,7 @@ static av_cold int libschroedinger_decode_init(AVCodecContext *avccontext)
return -1;
/* Initialize the decoded frame queue. */
ff_dirac_schro_queue_init(&p_schro_params->dec_frame_queue);
ff_schro_queue_init(&p_schro_params->dec_frame_queue);
return 0;
}
......@@ -267,7 +266,7 @@ static int libschroedinger_decode_frame(AVCodecContext *avccontext,
frame = schro_decoder_pull(decoder);
if (frame)
ff_dirac_schro_queue_push_back(&p_schro_params->dec_frame_queue,
ff_schro_queue_push_back(&p_schro_params->dec_frame_queue,
frame);
break;
case SCHRO_DECODER_EOS:
......@@ -285,7 +284,7 @@ static int libschroedinger_decode_frame(AVCodecContext *avccontext,
} while (outer);
/* Grab next frame to be returned from the top of the queue. */
frame = ff_dirac_schro_queue_pop(&p_schro_params->dec_frame_queue);
frame = ff_schro_queue_pop(&p_schro_params->dec_frame_queue);
if (frame) {
memcpy(p_schro_params->dec_pic.data[0],
......@@ -324,7 +323,7 @@ static av_cold int libschroedinger_decode_close(AVCodecContext *avccontext)
avpicture_free(&p_schro_params->dec_pic);
/* Free data in the output frame queue. */
ff_dirac_schro_queue_free(&p_schro_params->dec_frame_queue,
ff_schro_queue_free(&p_schro_params->dec_frame_queue,
libschroedinger_decode_frame_free);
return 0;
......@@ -337,10 +336,10 @@ static void libschroedinger_flush(AVCodecContext *avccontext)
SchroDecoderParams *p_schro_params = avccontext->priv_data;
/* Free data in the output frame queue. */
ff_dirac_schro_queue_free(&p_schro_params->dec_frame_queue,
ff_schro_queue_free(&p_schro_params->dec_frame_queue,
libschroedinger_decode_frame_free);
ff_dirac_schro_queue_init(&p_schro_params->dec_frame_queue);
ff_schro_queue_init(&p_schro_params->dec_frame_queue);
schro_decoder_reset(p_schro_params->decoder);
p_schro_params->eos_pulled = 0;
p_schro_params->eos_signalled = 0;
......
......@@ -36,7 +36,6 @@
#include "avcodec.h"
#include "internal.h"
#include "libdirac_libschro.h"
#include "libschroedinger.h"
#include "bytestream.h"
......@@ -65,7 +64,7 @@ typedef struct SchroEncoderParams {
int enc_buf_size;
/** queue storing encoded frames */
DiracSchroQueue enc_frame_queue;
FFSchroQueue enc_frame_queue;
/** end of sequence signalled */
int eos_signalled;
......@@ -236,7 +235,7 @@ static int libschroedinger_encode_init(AVCodecContext *avccontext)
schro_encoder_start(p_schro_params->encoder);
/* Initialize the encoded frame queue. */
ff_dirac_schro_queue_init(&p_schro_params->enc_frame_queue);
ff_schro_queue_init(&p_schro_params->enc_frame_queue);
return 0;
}
......@@ -261,7 +260,7 @@ static SchroFrame *libschroedinger_frame_from_data(AVCodecContext *avccontext,
static void SchroedingerFreeFrame(void *data)
{
DiracSchroEncodedFrame *enc_frame = data;
FFSchroEncodedFrame *enc_frame = data;
av_freep(&enc_frame->p_encbuf);
av_free(enc_frame);
......@@ -273,7 +272,7 @@ static int libschroedinger_encode_frame(AVCodecContext *avccontext, AVPacket *pk
int enc_size = 0;
SchroEncoderParams *p_schro_params = avccontext->priv_data;
SchroEncoder *encoder = p_schro_params->encoder;
struct DiracSchroEncodedFrame *p_frame_output = NULL;
struct FFSchroEncodedFrame *p_frame_output = NULL;
int go = 1;
SchroBuffer *enc_buf;
int presentation_frame;
......@@ -333,7 +332,7 @@ static int libschroedinger_encode_frame(AVCodecContext *avccontext, AVPacket *pk
}
/* Create output frame. */
p_frame_output = av_mallocz(sizeof(DiracSchroEncodedFrame));
p_frame_output = av_mallocz(sizeof(FFSchroEncodedFrame));
/* Set output data. */
p_frame_output->size = p_schro_params->enc_buf_size;
p_frame_output->p_encbuf = p_schro_params->enc_buf;
......@@ -345,7 +344,7 @@ static int libschroedinger_encode_frame(AVCodecContext *avccontext, AVPacket *pk
* through 17 represesent the frame number. */
p_frame_output->frame_num = AV_RB32(enc_buf->data + 13);
ff_dirac_schro_queue_push_back(&p_schro_params->enc_frame_queue,
ff_schro_queue_push_back(&p_schro_params->enc_frame_queue,
p_frame_output);
p_schro_params->enc_buf_size = 0;
p_schro_params->enc_buf = NULL;
......@@ -373,7 +372,7 @@ static int libschroedinger_encode_frame(AVCodecContext *avccontext, AVPacket *pk
p_schro_params->eos_pulled)
last_frame_in_sequence = 1;
p_frame_output = ff_dirac_schro_queue_pop(&p_schro_params->enc_frame_queue);
p_frame_output = ff_schro_queue_pop(&p_schro_params->enc_frame_queue);
if (!p_frame_output)
return 0;
......@@ -425,7 +424,7 @@ static int libschroedinger_encode_close(AVCodecContext *avccontext)
schro_encoder_free(p_schro_params->encoder);
/* Free data in the output frame queue. */
ff_dirac_schro_queue_free(&p_schro_params->enc_frame_queue,
ff_schro_queue_free(&p_schro_params->enc_frame_queue,
SchroedingerFreeFrame);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment