From e3710646f6557a1592fbffa910ebed674cd9edf0 Mon Sep 17 00:00:00 2001 From: deva Date: Tue, 17 May 2005 14:30:56 +0000 Subject: Added code, preparing threaded encoding. --- src/Makefile.am | 6 +++-- src/mov_encoder.cc | 35 ++++++++++++++++-------- src/mov_encoder.h | 13 +++++---- src/mov_encoder_thread.cc | 68 +++++++++++++++++++++++++++++++++++++++++++++++ src/mov_encoder_thread.h | 66 +++++++++++++++++++++++++++++++++++++++++++++ src/server.cc | 22 ++++++++------- 6 files changed, 183 insertions(+), 27 deletions(-) create mode 100644 src/mov_encoder_thread.cc create mode 100644 src/mov_encoder_thread.h (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am index 11f5416..2bdb4dc 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -31,7 +31,8 @@ miav_SOURCES = $(shell if [ $QT_CXXFLAGS ] ; then ../tools/MocList cc; fi ) \ dv1394.cc \ server_status.cc \ info_gui.cc \ - info_console.cc + info_console.cc \ + mov_encoder_thread.cc EXTRA_DIST = \ aboutwindow.h \ @@ -61,7 +62,8 @@ EXTRA_DIST = \ server_status.h \ info.h \ info_gui.h \ - info_console.h + info_console.h \ + mov_encoder_thread.h miav_LDADD := $(shell if [ $QT_CXXFLAGS ] ; then ../tools/MocList o; fi ) diff --git a/src/mov_encoder.cc b/src/mov_encoder.cc index fed2c40..bb24c5a 100644 --- a/src/mov_encoder.cc +++ b/src/mov_encoder.cc @@ -39,6 +39,9 @@ /* * $Log$ + * Revision 1.21 2005/05/17 14:30:56 deva + * Added code, preparing threaded encoding. + * * Revision 1.20 2005/05/16 16:00:57 deva * * Lots of stuff! @@ -94,7 +97,7 @@ //av_alloc_format_context //av_destruct_packet_nofree -MovEncoder::MovEncoder(const char *filename) +MovEncoder::MovEncoder() { // FIXME: Hmmm... should this be detected somewhere?! static int w = 720; @@ -116,14 +119,14 @@ MovEncoder::MovEncoder(const char *filename) // Allocate the output buffer. fame_buffer = new unsigned char [FAME_BUFFER_SIZE]; - + /* // Open output file f=fopen(filename, "wb"); if(!f) { - fprintf(stderr, "Failed to open output file [%s] due to teh following error: %s", filename, strerror(errno)); + fprintf(stderr, "Failed to open output file [%s] due to the following error: %s", filename, strerror(errno)); return; } - + */ // Open a new session of the fame library. // (If initialization was successful, it returns a non-null context which // can then be used for subsequent library calls.) @@ -204,27 +207,29 @@ MovEncoder::MovEncoder(const char *filename) MovEncoder::~MovEncoder() { + /* if(f) { // The file was opened. int written = fame_close(fame_context); fwrite(fame_buffer, written, 1, f); fclose(f); } + */ delete [] fame_buffer; delete [] yuv.y; delete [] yuv.u; delete [] yuv.v; } -void MovEncoder::encode(Frame *dvframe) +Frame *MovEncoder::encode(Frame *dvframe) { - encode_video(dvframe); - encode_audio(dvframe); + return encode_video(dvframe); + // encode_audio(dvframe); } -void MovEncoder::encode_video(Frame *dvframe) +Frame *MovEncoder::encode_video(Frame *dvframe) { - if(!f) return; // The file was not opened. - + // if(!f) return; // The file was not opened. + // Decode DV Frame to YUV422 int w = 720; int h = 576; @@ -281,13 +286,21 @@ void MovEncoder::encode_video(Frame *dvframe) } } + // Allocate a new frame for the output + Frame *output = new Frame(NULL, FAME_BUFFER_SIZE); + unsigned int pt = (unsigned int)output->data; + // Encode YUV frame and write it to disk. fame_start_frame(fame_context, &yuv, 0); int written; while((written = fame_encode_slice(fame_context))) { - fwrite(fame_buffer, written, 1, f); + // fwrite(fame_buffer, written, 1, f); + memcpy((void *)pt, fame_buffer, written); + pt += written; } fame_end_frame(fame_context,0); + + return output; } void MovEncoder::encode_audio(Frame *dvframe) diff --git a/src/mov_encoder.h b/src/mov_encoder.h index 457b577..24525f2 100644 --- a/src/mov_encoder.h +++ b/src/mov_encoder.h @@ -36,6 +36,9 @@ /* * $Log$ + * Revision 1.8 2005/05/17 14:30:56 deva + * Added code, preparing threaded encoding. + * * Revision 1.7 2005/05/09 16:40:20 deva * * Added optimize yuv conversion code @@ -71,16 +74,16 @@ #include "util.h" // size specifies the length of the buffer. -#define FAME_BUFFER_SIZE (2*1024*1024) // FIXME: One size fits all... +#define FAME_BUFFER_SIZE (2*720*576*4) // FIXME: One size fits all... class MovEncoder { public: - MovEncoder(const char *filename); + MovEncoder(); ~MovEncoder(); - void encode(Frame *frame); + Frame* encode(Frame *frame); private: - void encode_video(Frame *frame); + Frame *encode_video(Frame *frame); void encode_audio(Frame *frame); // buffer is the buffer where encoded data will be written to. It must be large @@ -94,7 +97,7 @@ class MovEncoder { // libdv decoder dv_decoder_t *dvdecoder; - unsigned char rgb[720*576*4]; + unsigned char rgb[FAME_BUFFER_SIZE]; }; #endif diff --git a/src/mov_encoder_thread.cc b/src/mov_encoder_thread.cc new file mode 100644 index 0000000..a913e7b --- /dev/null +++ b/src/mov_encoder_thread.cc @@ -0,0 +1,68 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * mov_encoder_thread.cc + * + * Tue May 17 16:00:01 CEST 2005 + * Copyright 2005 Bent Bisballe + * 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. + */ + +/* + * $Id$ + */ + +/* + * $Log$ + * Revision 1.1 2005/05/17 14:30:56 deva + * Added code, preparing threaded encoding. + * + */ + +#include +#include "mov_encoder_thread.h" + +MovEncoderThread::MovEncoderThread(const char *filename) +{ + file = open(filename, O_CREAT | O_EXCL); + + threads = 4; + + for(int cnt = 0; cnt < threads; cnt++) { + encs.push_back(new MovEncoder()); + } +} + +MovEncoderThread::~MovEncoderThread() +{ + for(int cnt = 0; cnt < threads; cnt++) { + delete encs[cnt]; + } + if(file) close(file); +} + +void MovEncoderThread::encode(Frame* frame) +{ + if(!file) return; + printf("Encoding frame!\n"); + Frame *enc_frame = encs[0]->encode(frame); + write(file, enc_frame->data, enc_frame->size); + +} diff --git a/src/mov_encoder_thread.h b/src/mov_encoder_thread.h new file mode 100644 index 0000000..22fb78c --- /dev/null +++ b/src/mov_encoder_thread.h @@ -0,0 +1,66 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * mov_encoder_thread.h + * + * Tue May 17 16:00:01 CEST 2005 + * Copyright 2005 Bent Bisballe + * 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. + */ + +/* + * $Id$ + */ + +/* + * $Log$ + * Revision 1.1 2005/05/17 14:30:56 deva + * Added code, preparing threaded encoding. + * + */ + +#include +#ifndef __MIAV_MOV_ENCODER_THREAD_H__ +#define __MIAV_MOV_ENCODER_THREAD_H__ + +#include +#include +#include +#include + +#include +using namespace std; + +#include "mov_encoder.h" + +class MovEncoderThread { +public: + MovEncoderThread(const char *filename); + ~MovEncoderThread(); + + void encode(Frame* frame); + +private: + int threads; + int file; + vector encs; +}; + +#endif/*__MIAV_MOV_ENCODER_THREAD_H__*/ diff --git a/src/server.cc b/src/server.cc index 370af2e..ee14132 100644 --- a/src/server.cc +++ b/src/server.cc @@ -31,6 +31,9 @@ /* * $Log$ + * Revision 1.15 2005/05/17 14:30:56 deva + * Added code, preparing threaded encoding. + * * Revision 1.14 2005/05/16 16:00:57 deva * * Lots of stuff! @@ -71,7 +74,8 @@ #include "miav_config.h" -#include "mov_encoder.h" +//#include "mov_encoder.h" +#include "mov_encoder_thread.h" #include "img_encoder.h" #include "server_status.h" @@ -181,9 +185,9 @@ struct tm }; */ -MovEncoder *newMovEncoder(char* cpr) +MovEncoderThread *newMovEncoder(char* cpr) { - MovEncoder *enc; + MovEncoderThread *enc; struct tm *ltime; time_t t = time(NULL); FILE *fp; @@ -202,7 +206,7 @@ MovEncoder *newMovEncoder(char* cpr) fprintf(stderr, "MIaV does not have write access to the server root [%s]\n", root->c_str()); fprintf(stderr, "Redirecting output to [/tmp/miav-%d.mpg]\n", r); sprintf(fname, "/tmp/miav-%d.mpg", r); - enc = new MovEncoder(fname); + enc = new MovEncoderThread(fname); return enc; } fclose(fp); @@ -214,7 +218,7 @@ MovEncoder *newMovEncoder(char* cpr) fprintf(stderr, "Illigal CPR, it must have length 11, it had lentgh %d\n", strlen(cpr)); fprintf(stderr, "Redirecting output to [/tmp/miav-%d.mpg]\n", r); sprintf(fname, "/tmp/miav-%d.mpg", r); - enc = new MovEncoder(fname); + enc = new MovEncoderThread(fname); return enc; } @@ -230,7 +234,7 @@ MovEncoder *newMovEncoder(char* cpr) fprintf(stderr, "Not possible to create subfolder %s\n", fname); fprintf(stderr, "Redirecting output to [/tmp/miav-%d.mpg]\n", r); sprintf(fname, "/tmp/miav-%d.mpg", r); - enc = new MovEncoder(fname); + enc = new MovEncoderThread(fname); return enc; } @@ -241,7 +245,7 @@ MovEncoder *newMovEncoder(char* cpr) fprintf(stderr, "Not possible to create subfolder %s\n", fname); fprintf(stderr, "Redirecting output to [/tmp/miav-%d.mpg]\n", r); sprintf(fname, "/tmp/miav-%d.mpg", r); - enc = new MovEncoder(fname); + enc = new MovEncoderThread(fname); return enc; } @@ -265,7 +269,7 @@ MovEncoder *newMovEncoder(char* cpr) } fprintf(stderr, "Success - using filename: [%s]\n", fname); fflush(stderr); - enc = new MovEncoder(fname); + enc = new MovEncoderThread(fname); return enc; } @@ -280,7 +284,7 @@ void newConnection(Socket *socket) n_header h; Frame *frame; Frame *freeze_frame = NULL; - MovEncoder *enc = NULL; + MovEncoderThread *enc = NULL; // unsigned char dvbuf[DVPACKAGE_SIZE]; frame = new Frame(NULL, DVPACKAGE_SIZE); -- cgit v1.2.3