diff options
author | deva <deva> | 2006-07-20 15:11:45 +0000 |
---|---|---|
committer | deva <deva> | 2006-07-20 15:11:45 +0000 |
commit | e1af275ed3fc5a3ab2e50be325e44bd2de705bea (patch) | |
tree | 304d59a6c336f337c41c86725880364901553e54 | |
parent | 7b997e9a988e1ef6fe41680dc90be545a9ed1710 (diff) |
Added the transcoder, formalized the video and audio formats in format.h
-rw-r--r-- | lib/Makefile.am | 2 | ||||
-rw-r--r-- | lib/format.h | 48 | ||||
-rw-r--r-- | lib/frame.cc | 4 | ||||
-rw-r--r-- | lib/frame.h | 24 | ||||
-rw-r--r-- | lib/libdv_wrapper.cc | 5 | ||||
-rw-r--r-- | lib/transcoder.cc | 100 | ||||
-rw-r--r-- | lib/transcoder.h | 41 |
7 files changed, 202 insertions, 22 deletions
diff --git a/lib/Makefile.am b/lib/Makefile.am index 6f01ef1..0707d08 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -20,6 +20,7 @@ libmiav_la_SOURCES = \ threadsafe_queue.cc \ threadsafe_queue_fifo.cc \ threadsafe_queue_priority.cc \ + transcoder.cc \ util.cc EXTRA_DIST = \ @@ -45,5 +46,6 @@ EXTRA_DIST = \ threadsafe_queue.h \ threadsafe_queue_fifo.h \ threadsafe_queue_priority.h \ + transcoder.h \ util.h diff --git a/lib/format.h b/lib/format.h new file mode 100644 index 0000000..6797cd6 --- /dev/null +++ b/lib/format.h @@ -0,0 +1,48 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * format.h + * + * Wed Jul 19 22:13:35 CEST 2006 + * Copyright 2006 Bent Bisballe Nyeng + * deva@aasimon.org + ****************************************************************************/ + +/* + * This file is part of MIaV. + * + * MIaV is free software; you can redistribute it and/or modify + * 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. + * + * MIaV 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 MIaV; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ +#ifndef __MIAV_FORMAT_H__ +#define __MIAV_FORMAT_H__ + +// VIDEO FORMATS +typedef enum { + VF_NONE = 0x00, // Dummy + VF_DV = 0x01, + VF_YUV422 = 0x02, + VF_YV12 = 0x03, + VF_RGB = 0x04, + VF_BRG0 = 0x05 +} video_format_t; + +// AUDIO FORMATS +typedef enum { + AF_NONE = 0x00, // Dummy + AF_DV = 0x01, // Audio data is in the DV video frame + AF_PCM_48KHZ_16BIT = 0x02, // Raw pcm data in 48khz and 16bit + AF_MP3 = 0x03 // Lame encoded audio +} audio_format_t; + +#endif/*__MIAV_FORMAT_H__*/ diff --git a/lib/frame.cc b/lib/frame.cc index 472a03a..3a6c1eb 100644 --- a/lib/frame.cc +++ b/lib/frame.cc @@ -30,8 +30,8 @@ #include <memory.h> #include <stdlib.h> -Frame::Frame(char *vframe, int vframesize, int vformat, - char *aframe, int aframesize, int aformat) +Frame::Frame(char *vframe, int vframesize, video_format_t vformat, + char *aframe, int aframesize, audio_format_t aformat) { // Video this->vframe = vframe; diff --git a/lib/frame.h b/lib/frame.h index ecfa308..8c8fe34 100644 --- a/lib/frame.h +++ b/lib/frame.h @@ -28,40 +28,28 @@ #ifndef __FRAME_H__ #define __FRAME_H__ +#include "format.h" + //#define START_USE_FRAME(x) x->usage++ //#define STOP_USE_FRAME(x) if(--x->usage == 0) delete x; x = NULL // Definition of vector #include <vector> -// VIDEO FORMATS -#define VF_NONE 0x00 -#define VF_DV 0x01 -#define VF_YUV422 0x02 -#define VF_YV12 0x03 -#define VF_RGB 0x04 -#define VF_BRG0 0x05 - -// AUDIO FORMATS -#define AF_NONE 0x00 // Dummy -#define AF_DV 0x01 // Audio data is in the DV video frame -#define AF_PCM_48KHZ_16BIT 0x02 // Raw pcm data in 48khz and 16bit -#define AF_MP3 0x03 // Lame encoded audio - class Frame { public: - Frame(char *aframe, int aframesize, int aformat, - char *vframe, int vframesize, int vformat); + Frame(char *vframe, int vframesize, video_format_t vformat, + char *aframe = NULL, int aframesize = 0, audio_format_t aformat = AF_NONE); // Video char* vframe; int vframesize; - int vformat; + video_format_t vformat; // Audio char *aframe; int aframesize; - int aformat; + audio_format_t aformat; /** * Old frame code... to be removed shortly diff --git a/lib/libdv_wrapper.cc b/lib/libdv_wrapper.cc index 11c641d..a056419 100644 --- a/lib/libdv_wrapper.cc +++ b/lib/libdv_wrapper.cc @@ -26,6 +26,8 @@ */ #include "libdv_wrapper.h" +#include "format.h" + //#define COLORSPACE_YV12 LibDVWrapper::LibDVWrapper(DV::Quality quality, @@ -94,7 +96,7 @@ Frame *LibDVWrapper::decode(Frame *input, DV::ColorSpace c) int size = 0; char* buf = NULL; - int type = VF_NONE; + video_format_t type = VF_NONE; DV::ColorSpace colorspace = c; switch(colorspace) { case DV::YUV: @@ -109,7 +111,6 @@ Frame *LibDVWrapper::decode(Frame *input, DV::ColorSpace c) pitches[1] = width / 2; pitches[2] = width / 2; #else - printf("!\n"); size = width*height*2; buf = new char[size]; type = VF_YUV422; diff --git a/lib/transcoder.cc b/lib/transcoder.cc new file mode 100644 index 0000000..edb4449 --- /dev/null +++ b/lib/transcoder.cc @@ -0,0 +1,100 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * transcoder.cc + * + * Wed Jul 19 22:11:02 CEST 2006 + * Copyright 2006 Bent Bisballe Nyeng + * deva@aasimon.org + ****************************************************************************/ + +/* + * This file is part of MIaV. + * + * MIaV is free software; you can redistribute it and/or modify + * 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. + * + * MIaV 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 MIaV; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ +#include "transcoder.h" + +/* + R = Y + 1.4075 * (V - 128) + G = Y - (0.3455 * (U - 128) - (0.7169 * (V - 128)) + B = Y + 1.7790 * (U - 128) +*/ +#define RED(y, u, v) (y + 1.4075 * (v - 128)) +#define GREEN(y, u, v) (y - (0.3455 * (u - 128)) - (0.7169 * (v - 128))) +#define BLUE(y, u, v) (y + 1.7790 * (u - 128)) + +/* + R = 1.164(Y - 16) + 1.596(V - 128) + G = 1.164(Y - 16) - 0.813(V - 128) - 0.391(U - 128) + B = 1.164(Y - 16) + 2.018(U - 128) +*/ +//#define RED(y, u, v) (1.164 * (y - 16) + 1.596 * (v - 128)) +//#define GREEN(y, u, v) (1.164 * (y - 16) - 0.813 * (v - 128) - 0.391 * (u - 128)) +//#define BLUE(y, u, v) (1.164 * (y - 16) + 2.018 * (u - 128)) +static Frame *transcode_yuv2brg0(Frame *input, char* rgb, int bufsz) +{ + if(!rgb) { // No buffer supplied, creating one. + rgb = new char[720 * 576 * 4]; + bufsz = 720 * 576 * 4; + } + if(bufsz < 720 * 576 * 4) return NULL; // Buffer is too small. + + unsigned char Y0, Y1, U, V; + + unsigned int byte = 0; + unsigned int pos = 0; + + char *pframe = input->vframe; + + while(pos < 720*576*4) { + // YUV 4:2:2 packing + // Y0 U0 Y1 V1 Y2 U2 Y3 V3 + // [Y0 U0 V1] [Y1 U0 V1] [Y2 U2 V3] [Y3 U2 V3] + + Y0 = pframe[byte]; byte++; + U = pframe[byte]; byte++; + Y1 = pframe[byte]; byte++; + V = pframe[byte]; byte++; + + rgb[pos+3] = 0; // Alpha + rgb[pos+2] = (unsigned char)RED(Y0, U, V); // Red + rgb[pos+1] = (unsigned char)GREEN(Y0, U, V); // Green + rgb[pos+0] = (unsigned char)BLUE(Y0, U, V); // Blue + pos+=4; + + rgb[pos+3] = 0; // Alpha + rgb[pos+2] = (unsigned char)RED(Y1, U, V); // Red + rgb[pos+1] = (unsigned char)GREEN(Y1, U, V); // Green + rgb[pos+0] = (unsigned char)BLUE(Y1, U, V); // Blue + pos+=4; + } + + return new Frame(rgb, bufsz, VF_BRG0, NULL, 0, AF_NONE); +} + + +Frame *transcode(Frame *input, + video_format_t vformat, char *vbuffer, int vbuffer_size, + audio_format_t aformat, char *abuffer, int abuffer_size) +{ + + // YUV422 => BRG0 + if(vformat == VF_BRG0 && input->vformat == VF_YUV422 && + aformat == AF_NONE && abuffer == NULL) + return transcode_yuv2brg0(input, vbuffer, vbuffer_size); + + // Unknown transcoding! + return NULL; +} diff --git a/lib/transcoder.h b/lib/transcoder.h new file mode 100644 index 0000000..9f3fab7 --- /dev/null +++ b/lib/transcoder.h @@ -0,0 +1,41 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * transcoder.h + * + * Wed Jul 19 22:11:01 CEST 2006 + * Copyright 2006 Bent Bisballe Nyeng + * deva@aasimon.org + ****************************************************************************/ + +/* + * This file is part of MIaV. + * + * MIaV is free software; you can redistribute it and/or modify + * 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. + * + * MIaV 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 MIaV; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ +#ifndef __MIAV_TRANSCODER_H__ +#define __MIAV_TRANSCODER_H__ + +#include "frame.h" + +// If the outputbuffers are supplied they will be used when creating the outputframe. +// If not, new buffer will be allocated. +// +// IMPORTANT: The caller is responsible for the freeing of the buffers. +// +Frame *transcode(Frame *input, + video_format_t vformat, char *vbuffer, int vbuffer_size, + audio_format_t aformat = AF_NONE, char *abuffer = NULL, int abuffer_size = 0); + +#endif/*__MIAV_TRANSCODER_H__*/ |