forked from silverfilain/x264_L-SMASH
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
split muxers.c into one file per format
simplify internal muxer API
- Loading branch information
Showing
15 changed files
with
1,319 additions
and
1,185 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
/***************************************************************************** | ||
* avis.c: x264 avi/avs input module | ||
***************************************************************************** | ||
* Copyright (C) 2003-2009 x264 project | ||
* | ||
* Authors: Laurent Aimar <fenrir@via.ecp.fr> | ||
* Loren Merritt <lorenm@u.washington.edu> | ||
* | ||
* This program 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. | ||
* | ||
* This program 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., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. | ||
*****************************************************************************/ | ||
|
||
#include "muxers.h" | ||
#include <windows.h> | ||
#include <vfw.h> | ||
|
||
typedef struct | ||
{ | ||
PAVISTREAM p_avi; | ||
int width, height; | ||
} avis_hnd_t; | ||
|
||
static int open_file( char *psz_filename, hnd_t *p_handle, x264_param_t *p_param ) | ||
{ | ||
avis_hnd_t *h = malloc( sizeof(avis_hnd_t) ); | ||
if( !h ) | ||
return -1; | ||
AVISTREAMINFO info; | ||
int i; | ||
|
||
*p_handle = h; | ||
|
||
AVIFileInit(); | ||
if( AVIStreamOpenFromFile( &h->p_avi, psz_filename, streamtypeVIDEO, 0, OF_READ, NULL ) ) | ||
{ | ||
AVIFileExit(); | ||
return -1; | ||
} | ||
|
||
if( AVIStreamInfo( h->p_avi, &info, sizeof(AVISTREAMINFO) ) ) | ||
{ | ||
AVIStreamRelease( h->p_avi ); | ||
AVIFileExit(); | ||
return -1; | ||
} | ||
|
||
// check input format | ||
if( info.fccHandler != MAKEFOURCC('Y', 'V', '1', '2') ) | ||
{ | ||
fprintf( stderr, "avis [error]: unsupported input format (%c%c%c%c)\n", | ||
(char)(info.fccHandler & 0xff), (char)((info.fccHandler >> 8) & 0xff), | ||
(char)((info.fccHandler >> 16) & 0xff), (char)((info.fccHandler >> 24)) ); | ||
|
||
AVIStreamRelease( h->p_avi ); | ||
AVIFileExit(); | ||
|
||
return -1; | ||
} | ||
|
||
h->width = | ||
p_param->i_width = info.rcFrame.right - info.rcFrame.left; | ||
h->height = | ||
p_param->i_height = info.rcFrame.bottom - info.rcFrame.top; | ||
i = gcd( info.dwRate, info.dwScale ); | ||
p_param->i_fps_den = info.dwScale / i; | ||
p_param->i_fps_num = info.dwRate / i; | ||
|
||
fprintf( stderr, "avis [info]: %dx%d @ %.2f fps (%d frames)\n", | ||
p_param->i_width, p_param->i_height, | ||
(double)p_param->i_fps_num / (double)p_param->i_fps_den, | ||
(int)info.dwLength ); | ||
|
||
return 0; | ||
} | ||
|
||
static int get_frame_total( hnd_t handle ) | ||
{ | ||
avis_hnd_t *h = handle; | ||
AVISTREAMINFO info; | ||
|
||
if( AVIStreamInfo( h->p_avi, &info, sizeof(AVISTREAMINFO) ) ) | ||
return -1; | ||
|
||
return info.dwLength; | ||
} | ||
|
||
static int read_frame( x264_picture_t *p_pic, hnd_t handle, int i_frame ) | ||
{ | ||
avis_hnd_t *h = handle; | ||
|
||
p_pic->img.i_csp = X264_CSP_YV12; | ||
|
||
if( AVIStreamRead( h->p_avi, i_frame, 1, p_pic->img.plane[0], h->width * h->height * 3 / 2, NULL, NULL ) ) | ||
return -1; | ||
|
||
return 0; | ||
} | ||
|
||
static int close_file( hnd_t handle ) | ||
{ | ||
avis_hnd_t *h = handle; | ||
AVIStreamRelease( h->p_avi ); | ||
AVIFileExit(); | ||
free( h ); | ||
return 0; | ||
} | ||
|
||
cli_input_t avis_input = { open_file, get_frame_total, read_frame, close_file }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/***************************************************************************** | ||
* input.h: x264 file input modules | ||
***************************************************************************** | ||
* Copyright (C) 2003-2009 x264 project | ||
* | ||
* Authors: Laurent Aimar <fenrir@via.ecp.fr> | ||
* Loren Merritt <lorenm@u.washington.edu> | ||
* | ||
* This program 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. | ||
* | ||
* This program 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., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. | ||
*****************************************************************************/ | ||
|
||
#ifndef X264_INPUT_H | ||
#define X264_INPUT_H | ||
|
||
typedef struct | ||
{ | ||
int (*open_file)( char *psz_filename, hnd_t *p_handle, x264_param_t *p_param ); | ||
int (*get_frame_total)( hnd_t handle ); | ||
int (*read_frame)( x264_picture_t *p_pic, hnd_t handle, int i_frame ); | ||
int (*close_file)( hnd_t handle ); | ||
} cli_input_t; | ||
|
||
extern cli_input_t yuv_input; | ||
extern cli_input_t y4m_input; | ||
extern cli_input_t avis_input; | ||
extern cli_input_t thread_input; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
/***************************************************************************** | ||
* thread.c: x264 threaded input module | ||
***************************************************************************** | ||
* Copyright (C) 2003-2009 x264 project | ||
* | ||
* Authors: Laurent Aimar <fenrir@via.ecp.fr> | ||
* Loren Merritt <lorenm@u.washington.edu> | ||
* | ||
* This program 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. | ||
* | ||
* This program 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., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. | ||
*****************************************************************************/ | ||
|
||
#include "muxers.h" | ||
|
||
extern cli_input_t input; | ||
|
||
typedef struct | ||
{ | ||
cli_input_t input; | ||
hnd_t p_handle; | ||
x264_picture_t pic; | ||
x264_pthread_t tid; | ||
int next_frame; | ||
int frame_total; | ||
int in_progress; | ||
struct thread_input_arg_t *next_args; | ||
} thread_hnd_t; | ||
|
||
typedef struct thread_input_arg_t | ||
{ | ||
thread_hnd_t *h; | ||
x264_picture_t *pic; | ||
int i_frame; | ||
int status; | ||
} thread_input_arg_t; | ||
|
||
static int open_file( char *psz_filename, hnd_t *p_handle, x264_param_t *p_param ) | ||
{ | ||
thread_hnd_t *h = malloc( sizeof(thread_hnd_t) ); | ||
if( !h || x264_picture_alloc( &h->pic, X264_CSP_I420, p_param->i_width, p_param->i_height ) < 0 ) | ||
{ | ||
fprintf( stderr, "x264 [error]: malloc failed\n" ); | ||
return -1; | ||
} | ||
h->input = input; | ||
h->p_handle = *p_handle; | ||
h->in_progress = 0; | ||
h->next_frame = -1; | ||
h->next_args = malloc( sizeof(thread_input_arg_t) ); | ||
if( !h->next_args ) | ||
return -1; | ||
h->next_args->h = h; | ||
h->next_args->status = 0; | ||
h->frame_total = input.get_frame_total( h->p_handle ); | ||
|
||
*p_handle = h; | ||
return 0; | ||
} | ||
|
||
static int get_frame_total( hnd_t handle ) | ||
{ | ||
thread_hnd_t *h = handle; | ||
return h->frame_total; | ||
} | ||
|
||
static void read_frame_thread_int( thread_input_arg_t *i ) | ||
{ | ||
i->status = i->h->input.read_frame( i->pic, i->h->p_handle, i->i_frame ); | ||
} | ||
|
||
static int read_frame( x264_picture_t *p_pic, hnd_t handle, int i_frame ) | ||
{ | ||
thread_hnd_t *h = handle; | ||
int ret = 0; | ||
|
||
if( h->next_frame >= 0 ) | ||
{ | ||
x264_pthread_join( h->tid, NULL ); | ||
ret |= h->next_args->status; | ||
h->in_progress = 0; | ||
} | ||
|
||
if( h->next_frame == i_frame ) | ||
XCHG( x264_picture_t, *p_pic, h->pic ); | ||
else | ||
ret |= h->input.read_frame( p_pic, h->p_handle, i_frame ); | ||
|
||
if( !h->frame_total || i_frame+1 < h->frame_total ) | ||
{ | ||
h->next_frame = | ||
h->next_args->i_frame = i_frame+1; | ||
h->next_args->pic = &h->pic; | ||
if( x264_pthread_create( &h->tid, NULL, (void*)read_frame_thread_int, h->next_args ) ) | ||
return -1; | ||
h->in_progress = 1; | ||
} | ||
else | ||
h->next_frame = -1; | ||
|
||
return ret; | ||
} | ||
|
||
static int close_file( hnd_t handle ) | ||
{ | ||
thread_hnd_t *h = handle; | ||
if( h->in_progress ) | ||
x264_pthread_join( h->tid, NULL ); | ||
h->input.close_file( h->p_handle ); | ||
x264_picture_clean( &h->pic ); | ||
free( h->next_args ); | ||
free( h ); | ||
return 0; | ||
} | ||
|
||
cli_input_t thread_input = { open_file, get_frame_total, read_frame, close_file }; |
Oops, something went wrong.