]> git.sesse.net Git - vlc/blob - modules/packetizer/mpegvideo.c
704f4d08d7cad2a28c39575e7dd7c6c957eeafab
[vlc] / modules / packetizer / mpegvideo.c
1 /*****************************************************************************
2  * mpegvideo.c: parse and packetize an MPEG1/2 video stream
3  *****************************************************************************
4  * Copyright (C) 2001-2006 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
8  *          Eric Petit <titer@videolan.org>
9  *          Gildas Bazin <gbazin@videolan.org>
10  *          Jean-Paul Saman <jpsaman #_at_# m2x dot nl>
11  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 2 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
25  *****************************************************************************/
26
27 /*****************************************************************************
28  * Problem with this implementation:
29  *
30  * Although we should time-stamp each picture with a PTS, this isn't possible
31  * with the current implementation.
32  * The problem comes from the fact that for non-low-delay streams we can't
33  * calculate the PTS of pictures used as backward reference. Even the temporal
34  * reference number doesn't help here because all the pictures don't
35  * necessarily have the same duration (eg. 3:2 pulldown).
36  *
37  * However this doesn't really matter as far as the MPEG muxers are concerned
38  * because they allow having empty PTS fields. --gibalou
39  *****************************************************************************/
40
41 /*****************************************************************************
42  * Preamble
43  *****************************************************************************/
44
45 #include <vlc/vlc.h>
46 #include <vlc_block.h>
47 #include <vlc_codec.h>
48 #include <vlc_block_helper.h>
49
50 #define SYNC_INTRAFRAME_TEXT N_("Sync on Intra Frame")
51 #define SYNC_INTRAFRAME_LONGTEXT N_("Normally the packetizer would " \
52     "sync on the next full frame. This flags instructs the packetizer " \
53     "to sync on the first Intra Frame found.")
54
55 /*****************************************************************************
56  * Module descriptor
57  *****************************************************************************/
58 static int  Open ( vlc_object_t * );
59 static void Close( vlc_object_t * );
60
61 vlc_module_begin();
62     set_category( CAT_SOUT );
63     set_subcategory( SUBCAT_SOUT_PACKETIZER );
64     set_description( _("MPEG-I/II video packetizer") );
65     set_capability( "packetizer", 50 );
66     set_callbacks( Open, Close );
67
68     add_bool( "packetizer-mpegvideo-sync-iframe", 0, NULL, SYNC_INTRAFRAME_TEXT,
69               SYNC_INTRAFRAME_LONGTEXT, VLC_TRUE );
70 vlc_module_end();
71
72 /*****************************************************************************
73  * Local prototypes
74  *****************************************************************************/
75 static block_t *Packetize( decoder_t *, block_t ** );
76 static block_t *ParseMPEGBlock( decoder_t *, block_t * );
77
78 struct decoder_sys_t
79 {
80     /*
81      * Input properties
82      */
83     block_bytestream_t bytestream;
84     int i_state;
85     int i_offset;
86     uint8_t p_startcode[3];
87
88     /* Sequence header and extension */
89     block_t *p_seq;
90     block_t *p_ext;
91
92     /* Current frame being built */
93     block_t    *p_frame;
94     block_t    **pp_last;
95
96     vlc_bool_t b_frame_slice;
97     mtime_t i_pts;
98     mtime_t i_dts;
99
100     /* Sequence properties */
101     int         i_frame_rate;
102     int         i_frame_rate_base;
103     vlc_bool_t  b_seq_progressive;
104     vlc_bool_t  b_low_delay;
105     int         i_aspect_ratio_info;
106     vlc_bool_t  b_inited;
107
108     /* Picture properties */
109     int i_temporal_ref;
110     int i_picture_type;
111     int i_picture_structure;
112     int i_top_field_first;
113     int i_repeat_first_field;
114     int i_progressive_frame;
115
116     mtime_t i_interpolated_dts;
117     mtime_t i_last_ref_pts;
118     vlc_bool_t b_second_field;
119
120     /* Number of pictures since last sequence header */
121     int i_seq_old;
122
123     /* Sync behaviour */
124     vlc_bool_t  b_sync_on_intra_frame;
125     vlc_bool_t  b_discontinuity;
126 };
127
128 enum {
129     STATE_NOSYNC,
130     STATE_NEXT_SYNC
131 };
132
133 /*****************************************************************************
134  * Open:
135  *****************************************************************************/
136 static int Open( vlc_object_t *p_this )
137 {
138     decoder_t *p_dec = (decoder_t*)p_this;
139     decoder_sys_t *p_sys;
140
141     if( p_dec->fmt_in.i_codec != VLC_FOURCC( 'm', 'p', 'g', '1' ) &&
142         p_dec->fmt_in.i_codec != VLC_FOURCC( 'm', 'p', 'g', '2' ) &&
143         p_dec->fmt_in.i_codec != VLC_FOURCC( 'm', 'p', 'g', 'v' ) )
144     {
145         return VLC_EGENERIC;
146     }
147
148     es_format_Init( &p_dec->fmt_out, VIDEO_ES, VLC_FOURCC('m','p','g','v') );
149     p_dec->pf_packetize = Packetize;
150
151     p_dec->p_sys = p_sys = malloc( sizeof( decoder_sys_t ) );
152
153     /* Misc init */
154     p_sys->i_state = STATE_NOSYNC;
155     p_sys->bytestream = block_BytestreamInit( p_dec );
156     p_sys->p_startcode[0] = 0;
157     p_sys->p_startcode[1] = 0;
158     p_sys->p_startcode[2] = 1;
159     p_sys->i_offset = 0;
160
161     p_sys->p_seq = NULL;
162     p_sys->p_ext = NULL;
163     p_sys->p_frame = NULL;
164     p_sys->pp_last = &p_sys->p_frame;
165     p_sys->b_frame_slice = VLC_FALSE;
166
167     p_sys->i_dts = p_sys->i_pts = 0;
168
169     p_sys->i_frame_rate = 1;
170     p_sys->i_frame_rate_base = 1;
171     p_sys->b_seq_progressive = VLC_TRUE;
172     p_sys->b_low_delay = VLC_TRUE;
173     p_sys->i_seq_old = 0;
174
175     p_sys->i_temporal_ref = 0;
176     p_sys->i_picture_type = 0;
177     p_sys->i_picture_structure = 0x03; /* frame */
178     p_sys->i_top_field_first = 0;
179     p_sys->i_repeat_first_field = 0;
180     p_sys->i_progressive_frame = 0;
181     p_sys->b_inited = 0;
182
183     p_sys->i_interpolated_dts = 0;
184     p_sys->i_last_ref_pts = 0;
185     p_sys->b_second_field = 0;
186
187     p_sys->b_discontinuity = VLC_FALSE;
188     p_sys->b_sync_on_intra_frame = var_CreateGetBool( p_dec, "packetizer-mpegvideo-sync-iframe" );
189     if( p_sys->b_sync_on_intra_frame )
190         msg_Dbg( p_dec, "syncing on intra frame now" );
191
192     return VLC_SUCCESS;
193 }
194
195 /*****************************************************************************
196  * Close:
197  *****************************************************************************/
198 static void Close( vlc_object_t *p_this )
199 {
200     decoder_t     *p_dec = (decoder_t*)p_this;
201     decoder_sys_t *p_sys = p_dec->p_sys;
202
203     block_BytestreamRelease( &p_sys->bytestream );
204
205     if( p_sys->p_seq )
206     {
207         block_Release( p_sys->p_seq );
208     }
209     if( p_sys->p_ext )
210     {
211         block_Release( p_sys->p_ext );
212     }
213     if( p_sys->p_frame )
214     {
215         block_ChainRelease( p_sys->p_frame );
216     }
217
218     var_Destroy( p_dec, "packetizer-mpegvideo-sync-iframe" );
219
220     free( p_sys );
221 }
222
223 /*****************************************************************************
224  * Packetize:
225  *****************************************************************************/
226 static block_t *Packetize( decoder_t *p_dec, block_t **pp_block )
227 {
228     decoder_sys_t *p_sys = p_dec->p_sys;
229     block_t       *p_pic;
230
231     if( pp_block == NULL || *pp_block == NULL )
232     {
233         return NULL;
234     }
235
236     if( (*pp_block)->i_flags&(BLOCK_FLAG_DISCONTINUITY|BLOCK_FLAG_CORRUPTED) )
237     {
238         if( (*pp_block)->i_flags&BLOCK_FLAG_CORRUPTED )
239         {
240             p_sys->i_state = STATE_NOSYNC;
241             block_BytestreamFlush( &p_sys->bytestream );
242
243             p_sys->b_discontinuity = VLC_TRUE;
244             if( p_sys->p_frame )
245                 block_ChainRelease( p_sys->p_frame );
246             p_sys->p_frame = NULL;
247             p_sys->pp_last = &p_sys->p_frame;
248             p_sys->b_frame_slice = VLC_FALSE;
249         }
250 //        p_sys->i_interpolated_dts =
251 //        p_sys->i_last_ref_pts = 0;
252
253         block_Release( *pp_block );
254         return NULL;
255     }
256
257
258     block_BytestreamPush( &p_sys->bytestream, *pp_block );
259
260     while( 1 )
261     {
262         switch( p_sys->i_state )
263         {
264
265         case STATE_NOSYNC:
266             if( block_FindStartcodeFromOffset( &p_sys->bytestream,
267                     &p_sys->i_offset, p_sys->p_startcode, 3 ) == VLC_SUCCESS )
268             {
269                 p_sys->i_state = STATE_NEXT_SYNC;
270             }
271
272             if( p_sys->i_offset )
273             {
274                 block_SkipBytes( &p_sys->bytestream, p_sys->i_offset );
275                 p_sys->i_offset = 0;
276                 block_BytestreamFlush( &p_sys->bytestream );
277             }
278
279             if( p_sys->i_state != STATE_NEXT_SYNC )
280             {
281                 /* Need more data */
282                 return NULL;
283             }
284
285             p_sys->i_offset = 1; /* To find next startcode */
286
287         case STATE_NEXT_SYNC:
288             /* TODO: If p_block == NULL, flush the buffer without checking the
289              * next sync word */
290
291             /* Find the next startcode */
292             if( block_FindStartcodeFromOffset( &p_sys->bytestream,
293                     &p_sys->i_offset, p_sys->p_startcode, 3 ) != VLC_SUCCESS )
294             {
295                 /* Need more data */
296                 return NULL;
297             }
298
299             /* Get the new fragment and set the pts/dts */
300             p_pic = block_New( p_dec, p_sys->i_offset );
301             block_BytestreamFlush( &p_sys->bytestream );
302             p_pic->i_pts = p_sys->bytestream.p_block->i_pts;
303             p_pic->i_dts = p_sys->bytestream.p_block->i_dts;
304
305             block_GetBytes( &p_sys->bytestream, p_pic->p_buffer,
306                             p_pic->i_buffer );
307
308             /* don't reuse the same timestamps several times */
309             if( p_pic->i_buffer >= 4 && p_pic->p_buffer[3] == 0x00 )
310             {
311                 /* We have a picture start code */
312                 p_sys->bytestream.p_block->i_pts = 0;
313                 p_sys->bytestream.p_block->i_dts = 0;
314             }
315
316             p_sys->i_offset = 0;
317
318             /* Get picture if any */
319             if( !( p_pic = ParseMPEGBlock( p_dec, p_pic ) ) )
320             {
321                 p_sys->i_state = STATE_NOSYNC;
322                 break;
323             }
324
325             /* If a discontinuity has been encountered, then wait till
326              * the next Intra frame before continuing with packetizing */
327             if( p_sys->b_discontinuity &&
328                 p_sys->b_sync_on_intra_frame )
329             {
330                 if( p_pic->i_flags & BLOCK_FLAG_TYPE_I )
331                 {
332                     msg_Dbg( p_dec, "synced on intra frame" );
333                     p_sys->b_discontinuity = VLC_FALSE;
334                     p_pic->i_flags |= BLOCK_FLAG_DISCONTINUITY;
335                 }
336                 else
337                 {
338                     msg_Dbg( p_dec, "waiting on intra frame" );
339                     p_sys->i_state = STATE_NOSYNC;
340                     block_Release( p_pic );
341                     break;
342                 }
343             }
344
345             /* We've just started the stream, wait for the first PTS.
346              * We discard here so we can still get the sequence header. */
347             if( p_sys->i_dts <= 0 && p_sys->i_pts <= 0 &&
348                 p_sys->i_interpolated_dts <= 0 )
349             {
350                 msg_Dbg( p_dec, "need a starting pts/dts" );
351                 p_sys->i_state = STATE_NOSYNC;
352                 block_Release( p_pic );
353                 break;
354             }
355
356             /* When starting the stream we can have the first frame with
357              * a null DTS (i_interpolated_pts is initialized to 0) */
358             if( !p_pic->i_dts ) p_pic->i_dts = p_pic->i_pts;
359
360             /* So p_block doesn't get re-added several times */
361             *pp_block = block_BytestreamPop( &p_sys->bytestream );
362
363             p_sys->i_state = STATE_NOSYNC;
364
365             return p_pic;
366         }
367     }
368 }
369
370 /*****************************************************************************
371  * ParseMPEGBlock: Re-assemble fragments into a block containing a picture
372  *****************************************************************************/
373 static block_t *ParseMPEGBlock( decoder_t *p_dec, block_t *p_frag )
374 {
375     decoder_sys_t *p_sys = p_dec->p_sys;
376     block_t *p_pic = NULL;
377
378     /*
379      * Check if previous picture is finished
380      */
381     if( ( p_sys->b_frame_slice &&
382           (p_frag->p_buffer[3] == 0x00 || p_frag->p_buffer[3] > 0xaf) ) &&
383           p_sys->p_seq == NULL )
384     {
385         /* We have a picture but without a sequence header we can't
386          * do anything */
387         msg_Dbg( p_dec, "waiting for sequence start" );
388         if( p_sys->p_frame ) block_ChainRelease( p_sys->p_frame );
389         p_sys->p_frame = NULL;
390         p_sys->pp_last = &p_sys->p_frame;
391         p_sys->b_frame_slice = VLC_FALSE;
392
393     }
394     else if( p_sys->b_frame_slice &&
395              (p_frag->p_buffer[3] == 0x00 || p_frag->p_buffer[3] > 0xaf) )
396     {
397         mtime_t i_duration;
398
399         p_pic = block_ChainGather( p_sys->p_frame );
400
401         i_duration = (mtime_t)( 1000000 * p_sys->i_frame_rate_base /
402                                 p_sys->i_frame_rate );
403
404         if( !p_sys->b_seq_progressive && p_sys->i_picture_structure != 0x03 )
405         {
406             i_duration /= 2;
407         }
408
409         if( p_sys->b_seq_progressive )
410         {
411             if( p_sys->i_top_field_first == 0 &&
412                 p_sys->i_repeat_first_field == 1 )
413             {
414                 i_duration *= 2;
415             }
416             else if( p_sys->i_top_field_first == 1 &&
417                      p_sys->i_repeat_first_field == 1 )
418             {
419                 i_duration *= 3;
420             }
421         }
422         else
423         {
424             if( p_sys->i_picture_structure == 0x03 )
425             {
426                 if( p_sys->i_progressive_frame && p_sys->i_repeat_first_field )
427                 {
428                     i_duration += i_duration / 2;
429                 }
430             }
431         }
432
433         if( p_sys->b_low_delay || p_sys->i_picture_type == 0x03 )
434         {
435             /* Trivial case (DTS == PTS) */
436             /* Correct interpolated dts when we receive a new pts/dts */
437             if( p_sys->i_pts > 0 ) p_sys->i_interpolated_dts = p_sys->i_pts;
438             if( p_sys->i_dts > 0 ) p_sys->i_interpolated_dts = p_sys->i_dts;
439         }
440         else
441         {
442             /* Correct interpolated dts when we receive a new pts/dts */
443             if( p_sys->i_last_ref_pts > 0 && !p_sys->b_second_field )
444                 p_sys->i_interpolated_dts = p_sys->i_last_ref_pts;
445             if( p_sys->i_dts > 0 ) p_sys->i_interpolated_dts = p_sys->i_dts;
446
447             if( !p_sys->b_second_field )
448                 p_sys->i_last_ref_pts = p_sys->i_pts;
449         }
450
451         p_pic->i_dts = p_sys->i_interpolated_dts;
452         p_sys->i_interpolated_dts += i_duration;
453
454         /* Set PTS only if we have a B frame or if it comes from the stream */
455         if( p_sys->i_pts > 0 )
456         {
457             p_pic->i_pts = p_sys->i_pts;
458         }
459         else if( p_sys->i_picture_type == 0x03 )
460         {
461             p_pic->i_pts = p_pic->i_dts;
462         }
463         else
464         {
465             p_pic->i_pts = 0;
466         }
467
468         switch ( p_sys->i_picture_type )
469         {
470         case 0x01:
471             p_pic->i_flags |= BLOCK_FLAG_TYPE_I;
472             break;
473         case 0x02:
474             p_pic->i_flags |= BLOCK_FLAG_TYPE_P;
475             break;
476         case 0x03:
477             p_pic->i_flags |= BLOCK_FLAG_TYPE_B;
478             break;
479         }
480
481         p_pic->i_length = p_sys->i_interpolated_dts - p_pic->i_dts;
482
483 #if 0
484         msg_Dbg( p_dec, "pic: type=%d dts="I64Fd" pts-dts="I64Fd,
485         p_sys->i_picture_type, p_pic->i_dts, p_pic->i_pts - p_pic->i_dts);
486 #endif
487
488         /* Reset context */
489         p_sys->p_frame = NULL;
490         p_sys->pp_last = &p_sys->p_frame;
491         p_sys->b_frame_slice = VLC_FALSE;
492
493         if( p_sys->i_picture_structure != 0x03 )
494         {
495             p_sys->b_second_field = !p_sys->b_second_field;
496         }
497         else
498         {
499             p_sys->b_second_field = 0;
500         }
501     }
502
503     /*
504      * Check info of current fragment
505      */
506     if( p_frag->p_buffer[3] == 0xb8 )
507     {
508         /* Group start code */
509         if( p_sys->p_seq &&
510             p_sys->i_seq_old > p_sys->i_frame_rate/p_sys->i_frame_rate_base )
511         {
512             /* Usefull for mpeg1: repeat sequence header every second */
513             block_ChainLastAppend( &p_sys->pp_last, block_Duplicate( p_sys->p_seq ) );
514             if( p_sys->p_ext )
515             {
516                 block_ChainLastAppend( &p_sys->pp_last, block_Duplicate( p_sys->p_ext ) );
517             }
518
519             p_sys->i_seq_old = 0;
520         }
521     }
522     else if( p_frag->p_buffer[3] == 0xb3 && p_frag->i_buffer >= 8 )
523     {
524         /* Sequence header code */
525         static const int code_to_frame_rate[16][2] =
526         {
527             { 1, 1 },  /* invalid */
528             { 24000, 1001 }, { 24, 1 }, { 25, 1 },       { 30000, 1001 },
529             { 30, 1 },       { 50, 1 }, { 60000, 1001 }, { 60, 1 },
530             /* Unofficial 15fps from Xing*/
531             { 15, 1001 },
532             /* Unofficial economy rates from libmpeg3 */
533             { 5, 1001 }, { 10, 1001 }, { 12, 1001 }, { 15, 1001 },
534             { 1, 1 },  { 1, 1 }  /* invalid */
535         };
536
537         if( p_sys->p_seq ) block_Release( p_sys->p_seq );
538         if( p_sys->p_ext ) block_Release( p_sys->p_ext );
539
540         p_sys->p_seq = block_Duplicate( p_frag );
541         p_sys->i_seq_old = 0;
542         p_sys->p_ext = NULL;
543
544         p_dec->fmt_out.video.i_width =
545             ( p_frag->p_buffer[4] << 4)|(p_frag->p_buffer[5] >> 4 );
546         p_dec->fmt_out.video.i_height =
547             ( (p_frag->p_buffer[5]&0x0f) << 8 )|p_frag->p_buffer[6];
548         p_sys->i_aspect_ratio_info = p_frag->p_buffer[7] >> 4;
549
550         /* TODO: MPEG1 aspect ratio */
551
552         p_sys->i_frame_rate = code_to_frame_rate[p_frag->p_buffer[7]&0x0f][0];
553         p_sys->i_frame_rate_base =
554             code_to_frame_rate[p_frag->p_buffer[7]&0x0f][1];
555
556         p_dec->fmt_out.video.i_frame_rate = p_sys->i_frame_rate;
557         p_dec->fmt_out.video.i_frame_rate_base = p_sys->i_frame_rate_base;
558
559         p_sys->b_seq_progressive = VLC_TRUE;
560         p_sys->b_low_delay = VLC_TRUE;
561
562         if ( !p_sys->b_inited )
563         {
564             msg_Dbg( p_dec, "size %dx%d fps=%.3f",
565                  p_dec->fmt_out.video.i_width, p_dec->fmt_out.video.i_height,
566                  p_sys->i_frame_rate / (float)p_sys->i_frame_rate_base );
567             p_sys->b_inited = 1;
568         }
569     }
570     else if( p_frag->p_buffer[3] == 0xb5 )
571     {
572         int i_type = p_frag->p_buffer[4] >> 4;
573
574         /* Extension start code */
575         if( i_type == 0x01 )
576         {
577 #if 0
578             static const int mpeg2_aspect[16][2] =
579             {
580                 {0,1}, {1,1}, {4,3}, {16,9}, {221,100},
581                 {0,1}, {0,1}, {0,1}, {0,1}, {0,1}, {0,1}, {0,1}, {0,1}, {0,1},
582                 {0,1}, {0,1}
583             };
584 #endif
585
586             /* sequence extension */
587             if( p_sys->p_ext) block_Release( p_sys->p_ext );
588             p_sys->p_ext = block_Duplicate( p_frag );
589
590             if( p_frag->i_buffer >= 10 )
591             {
592                 p_sys->b_seq_progressive =
593                     p_frag->p_buffer[5]&0x08 ? VLC_TRUE : VLC_FALSE;
594                 p_sys->b_low_delay =
595                     p_frag->p_buffer[9]&0x80 ? VLC_TRUE : VLC_FALSE;
596             }
597
598             /* Do not set aspect ratio : in case we're transcoding,
599              * transcode will take our fmt_out as a fmt_in to libmpeg2.
600              * libmpeg2.c will then believe that the user has requested
601              * a specific aspect ratio, which she hasn't. Thus in case
602              * of aspect ratio change, we're screwed. --Meuuh
603              */
604 #if 0
605             p_dec->fmt_out.video.i_aspect =
606                 mpeg2_aspect[p_sys->i_aspect_ratio_info][0] *
607                 VOUT_ASPECT_FACTOR /
608                 mpeg2_aspect[p_sys->i_aspect_ratio_info][1];
609 #endif
610
611         }
612         else if( i_type == 0x08 )
613         {
614             /* picture extension */
615             p_sys->i_picture_structure = p_frag->p_buffer[6]&0x03;
616             p_sys->i_top_field_first   = p_frag->p_buffer[7] >> 7;
617             p_sys->i_repeat_first_field= (p_frag->p_buffer[7]>>1)&0x01;
618             p_sys->i_progressive_frame = p_frag->p_buffer[8] >> 7;
619         }
620     }
621     else if( p_frag->p_buffer[3] == 0x00 )
622     {
623         /* Picture start code */
624         p_sys->i_seq_old++;
625
626         if( p_frag->i_buffer >= 6 )
627         {
628             p_sys->i_temporal_ref =
629                 ( p_frag->p_buffer[4] << 2 )|(p_frag->p_buffer[5] >> 6);
630             p_sys->i_picture_type = ( p_frag->p_buffer[5] >> 3 ) & 0x03;
631         }
632
633         p_sys->i_dts = p_frag->i_dts;
634         p_sys->i_pts = p_frag->i_pts;
635     }
636     else if( p_frag->p_buffer[3] >= 0x01 && p_frag->p_buffer[3] <= 0xaf )
637     {
638         /* Slice start code */
639         p_sys->b_frame_slice = VLC_TRUE;
640     }
641
642     /* Append the block */
643     block_ChainLastAppend( &p_sys->pp_last, p_frag );
644
645     return p_pic;
646 }