1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
/* $Id: Resizer.cpp,v 1.3 2003/09/30 14:38:15 titer Exp $
This file is part of the HandBrake source code.
Homepage: <http://beos.titer.org/handbrake/>.
It may be used under the terms of the GNU General Public License. */
#include "Resizer.h"
#include "Manager.h"
#include "Fifo.h"
#include <ffmpeg/avcodec.h>
HBResizer::HBResizer( HBManager * manager, HBTitle * title )
: HBThread( "resizer" )
{
fManager = manager;
fTitle = title;
}
void HBResizer::DoWork()
{
/* Init libavcodec */
ImgReSampleContext * resampleContext =
img_resample_full_init( fTitle->fOutWidth, fTitle->fOutHeight,
fTitle->fInWidth, fTitle->fInHeight,
fTitle->fTopCrop, fTitle->fBottomCrop,
fTitle->fLeftCrop, fTitle->fRightCrop );
/* Buffers & pictures */
HBBuffer * rawBuffer, * deinterlacedBuffer, * resizedBuffer;
AVPicture rawPicture, deinterlacedPicture, resizedPicture;
deinterlacedBuffer = new HBBuffer( 3 * fTitle->fInWidth *
fTitle->fInHeight / 2 );
avpicture_fill( &deinterlacedPicture, deinterlacedBuffer->fData,
PIX_FMT_YUV420P, fTitle->fInWidth,
fTitle->fInHeight );
for( ;; )
{
while( fSuspend )
{
Snooze( 10000 );
}
if( !( rawBuffer = Pop( fTitle->fRawFifo ) ) )
{
break;
}
avpicture_fill( &rawPicture, rawBuffer->fData,
PIX_FMT_YUV420P, fTitle->fInWidth,
fTitle->fInHeight );
resizedBuffer = new HBBuffer( 3 * fTitle->fOutWidth *
fTitle->fOutHeight / 2 );
resizedBuffer->fPosition = rawBuffer->fPosition;
resizedBuffer->fPass = rawBuffer->fPass;
avpicture_fill( &resizedPicture, resizedBuffer->fData,
PIX_FMT_YUV420P, fTitle->fOutWidth,
fTitle->fOutHeight );
if( fTitle->fDeinterlace )
{
avpicture_deinterlace( &deinterlacedPicture, &rawPicture,
PIX_FMT_YUV420P,
fTitle->fInWidth,
fTitle->fInHeight );
img_resample( resampleContext, &resizedPicture,
&deinterlacedPicture );
}
else
{
img_resample( resampleContext, &resizedPicture,
&rawPicture );
}
Push( fTitle->fResizedFifo, resizedBuffer );
delete rawBuffer;
}
/* Free memory */
delete deinterlacedBuffer;
/* Close libavcodec */
img_resample_close( resampleContext );
}
|