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 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216
|
/*
* stillsstreams.c: Class for elemenary still video streams
* Most functionality is inherited from VideoStream
*
* Copyright (C) 2001 Andrew Stevens <andrew.stevens@philips.com>
*
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 2 of the GNU General Public License
* as published by the Free Software Foundation.
*
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <format_codes.h>
#include "stillsstream.hpp"
#include "interact.hpp"
#include "multiplexor.hpp"
void StillsStream::Init ( )
{
int stream_id = -1;
int buffer_size = -1;
SetBufSize( 4*1024*1024 );
ScanFirstSeqHeader();
mjpeg_debug( "Stills: Video buffer suggestion ignored!" );
switch( muxinto.mux_format )
{
case MPEG_FORMAT_VCD_STILL :
if( horizontal_size > 352 )
{
stream_id = VIDEO_STR_0+2 ;
buffer_size = vbv_buffer_size*2048;
mjpeg_info( "Stills Stream %02x: high-resolution VCD stills %d KB each",
stream_id,
buffer_size );
if( buffer_size < 46*1024 )
mjpeg_error_exit1( "I Can't multiplex high-res stills smaller than normal res stills - sorry!");
}
else
{
stream_id = VIDEO_STR_0+1 ;
buffer_size = 46*1024;
mjpeg_info( "Stills Stream %02x: normal VCD stills", stream_id );
}
break;
case MPEG_FORMAT_SVCD_STILL :
if( horizontal_size > 480 )
{
stream_id = VIDEO_STR_0+1;
buffer_size = 230*1024;
mjpeg_info( "Stills Stream %02x: high-resolution SVCD stills.",
stream_id );
}
else
{
stream_id = VIDEO_STR_0+1 ;
buffer_size = 230*1024;
mjpeg_info( "Stills Stream %02x: normal-resolution SVCD stills.", stream_id );
}
break;
default:
mjpeg_error_exit1( "Only SVCD and VCD Still currently supported");
}
MuxStream::Init( stream_id,
1, // Buffer scale
buffer_size,
0, // Zero stuffing
muxinto.buffers_in_video,
muxinto.always_buffers_in_video);
/* Skip to the end of the 1st AU (*2nd* Picture start!)
*/
AU_hdr = SEQUENCE_HEADER;
AU_pict_data = 0;
AU_start = 0;
OutputSeqhdrInfo();
}
/*
* Compute DTS / PTS for a VCD/SVCD Stills sequence
* TODO: Very crude. Simply assumes each still stays for the specified
* frame interval and that enough run-in delay is present for the first
* frame to be loaded.
*
*/
void StillsStream::NextDTSPTS( )
{
StillsParams *sparms = static_cast<StillsParams*>(parms);
clockticks interval = static_cast<clockticks>
(sparms->Intervals()->NextFrameInterval() * CLOCKS / frame_rate);
clockticks time_for_xfer;
muxinto.ByteposTimecode( BufferSize(), time_for_xfer );
access_unit.DTS = current_PTS + time_for_xfer; // This frame decoded just after
// Predecessor completed.
access_unit.PTS = current_PTS + time_for_xfer + interval;
current_PTS = access_unit.PTS;
current_DTS = access_unit.DTS;
fields_presented += 2;
}
/*
* VCD mixed stills segment items have the constraint that both stills
* streams must end together. To do this each stream has to know
* about its "sibling".
*
*/
void VCDStillsStream::SetSibling( VCDStillsStream *_sibling )
{
assert( _sibling != 0 );
sibling = _sibling;
if( sibling->stream_id == stream_id )
{
mjpeg_error_exit1("VCD mixed stills stream cannot contain two streams of the same type!");
}
}
/*
* Check if we've reached the last sector of the last AU. Note: that
* we know no PTS/DTS time-stamps will be needed because no new AU
* will appear in the last sector. WARNING: We assume a still won't
* fit into a single secotr.
*
*/
bool VCDStillsStream::LastSectorLastAU()
{
return ( Lookahead() == 0 &&
au_unsent <= muxinto.PacketPayload( *this,
buffers_in_header,
false, false )
);
}
/*
* The requirement that VCD mixed stills segment items constituent streams
* end together means we can't mux the last sector of the last AU of
* such streams until its sibling has already completed muxing or is
* also ready to mux the last sector of its last AU.
*
* NOTE: Will not work right if sector_align_iframe_AUs not set as this
* will allow multiple AU's in a sector.
*
*/
bool VCDStillsStream::MuxPossible(clockticks currentSCR)
{
if( bufmodel.Size() < au_unsent )
{
mjpeg_error_exit1( "Illegal VCD still: larger than maximum permitted by its buffering parameters!");
}
if (RunOutComplete() || bufmodel.Space() < au_unsent)
{
return false;
}
if( LastSectorLastAU() )
{
if( sibling != 0 )
{
if( !stream_mismatch_warned && sibling->NextAUType() != NOFRAME )
{
mjpeg_warn( "One VCD stills stream runs significantly longer than the other!");
mjpeg_warn( "Simultaneous stream ending recommended by standard not possible" );
return true;
}
return sibling->MuxCompleted() || sibling->LastSectorLastAU();
}
else
return true;
}
else
return true;
}
/*
* Local variables:
* c-file-style: "stroustrup"
* tab-width: 4
* indent-tabs-mode: nil
* End:
*/
|