long Nes_Rewinder::read_samples( short* out, long out_size ) { int count = samples_avail(); if ( count ) { if ( count > out_size ) { count = out_size; } if ( !reverse_enabled ) { memcpy( out, frames [current_frame].samples, count * sizeof *out ); } else { int step = samples_per_frame(); for ( int i = step; i-- > 0; ) copy_reverse( frames [current_frame].samples + i, count, out + i, step ); } if ( fade_sound_in ) { fade_sound_in = false; fade_samples_( out, count, 1 ); } if ( frames [current_frame].fade_out ) { fade_sound_in = true; fade_samples_( out, count, -1 ); } } return count; }
static gboolean process (GeglOperation *operation, GeglBuffer *output, const GeglRectangle *result, gint level) { GeglProperties *o = GEGL_PROPERTIES (operation); Priv *p = (Priv*)o->user_data; { if (p->video_fcontext && !decode_frame (operation, o->frame)) { long sample_start = 0; if (p->audio_stream) { int sample_count; gegl_audio_fragment_set_sample_rate (o->audio, p->audio_stream->codec->sample_rate); gegl_audio_fragment_set_channels (o->audio, 2); gegl_audio_fragment_set_channel_layout (o->audio, GEGL_CH_LAYOUT_STEREO); sample_count = samples_per_frame (o->frame, o->frame_rate, p->audio_stream->codec->sample_rate, &sample_start); gegl_audio_fragment_set_sample_count (o->audio, sample_count); decode_audio (operation, p->prevpts, p->prevpts + 5.0); { int i; for (i = 0; i < sample_count; i++) { get_sample_data (p, sample_start + i, &o->audio->data[0][i], &o->audio->data[1][i]); } } } if (p->video_stream->codec->pix_fmt == AV_PIX_FMT_RGB24) { GeglRectangle extent = {0,0,p->width,p->height}; gegl_buffer_set (output, &extent, 0, babl_format("R'G'B' u8"), p->lavc_frame->data[0], GEGL_AUTO_ROWSTRIDE); } else { struct SwsContext *img_convert_ctx; GeglRectangle extent = {0,0,p->width,p->height}; img_convert_ctx = sws_getContext(p->width, p->height, p->video_stream->codec->pix_fmt, p->width, p->height, AV_PIX_FMT_RGB24, SWS_BICUBIC, NULL, NULL, NULL); if (!p->rgb_frame) p->rgb_frame = alloc_picture (AV_PIX_FMT_RGB24, p->width, p->height); sws_scale (img_convert_ctx, (void*)p->lavc_frame->data, p->lavc_frame->linesize, 0, p->height, p->rgb_frame->data, p->rgb_frame->linesize); gegl_buffer_set (output, &extent, 0, babl_format("R'G'B' u8"), p->rgb_frame->data[0], GEGL_AUTO_ROWSTRIDE); sws_freeContext (img_convert_ctx); } } } return TRUE; }