Changeset 198

Show
Ignore:
Timestamp:
01/16/08 13:41:11 (4 years ago)
Author:
ath
Message:

Big FmInputGst updates.

Location:
fm_server/trunk/src/fm_input_gst
Files:
6 modified

Legend:

Unmodified
Added
Removed
  • fm_server/trunk/src/fm_input_gst/fm_input_gst.c

    r187 r198  
    11/* 
    22 *  FreeMix - sound server 
    3  *  Copyright (C) 2006 Alberto Botti <alberto.botti@yoda2000.net> 
     3 *  Copyright (C) 2007-2008 Alberto Botti <alberto.botti@yoda2000.net> 
    44 * 
    55 *  This program is free software; you can redistribute it and/or modify 
     
    1616 *  along with this program; if not, write to the Free Software 
    1717 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
     18 * 
     19 *  fm_input_gst.c - GStreamer input element 
    1820 */ 
    1921 
     
    6668gboolean fm_input_gst_deactivate        (FmElement      *element); 
    6769static void fm_input_gst_get_buffer     (FmElement      *element, 
    68                                          FmBuffer       *buffer); 
     70                                         FmBuffer       *buffer, 
     71                                         FmSync         *sync); 
    6972static void fm_input_gst_set_state      (FmInput        *input, 
    7073                                         FmInputState   new_state); 
     
    7376                                         GstMessage     *message, 
    7477                                         gpointer       data); 
    75 static void fm_input_gst_become_sync_master (FmElement  *element); 
     78//static void fm_input_gst_become_sync_master (FmElement        *element); 
    7679 
    7780 
     
    150153        element_class->deactivate = NULL; 
    151154        element_class->get_buffer = fm_input_gst_get_buffer; 
    152         element_class->become_sync_master = fm_input_gst_become_sync_master; 
     155//      element_class->become_sync_master = fm_input_gst_become_sync_master; 
    153156 
    154157        input_class->set_state = fm_input_gst_set_state; 
     
    178181{ 
    179182        g_print ("RESET STATUS!\n"); 
    180         input_gst->current_pos_samples = 0; 
     183//      input_gst->current_pos_samples = 0; 
     184        input_gst->current_pos_nsec = 0; 
    181185        input_gst->seek_at_nsec = -1; 
    182186 
     
    499503static void 
    500504fm_input_gst_get_buffer                 (FmElement      *element, 
    501                                          FmBuffer       *buffer) 
     505                                         FmBuffer       *buffer, 
     506                                         FmSync         *sync) 
    502507{ 
    503508        FmInputGst *input_gst = FM_INPUT_GST(element); 
     
    507512 
    508513 
     514        fm_buffer_reset_flags (buffer); 
     515 
     516        guint64 current_pos_samples = ns_to_samples (common, input_gst->current_pos_nsec); 
     517 
    509518        /* Check if we should perform a seek */ 
    510519        if ((input_gst->seek_at_nsec > -1) && chk){ 
    511                 glong first_avail_sample = input_gst->current_pos_samples - BYTES_TO_SAMPLES(chk->bytes_behind_us); 
    512                 glong last_avail_sample = input_gst->current_pos_samples + BYTES_TO_SAMPLES(jack_ringbuffer_read_space(chk->ring));  // we need an offset 
     520                /* We need to convert everything here down to samples and then to bytes */ 
     521                glong first_avail_sample = current_pos_samples - BYTES_TO_SAMPLES(chk->bytes_behind_us); 
     522                glong last_avail_sample = current_pos_samples + BYTES_TO_SAMPLES(jack_ringbuffer_read_space(chk->ring));  // we'll need an offset 
    513523             
    514524                guint64 seek_at_sample = ns_to_samples (common, input_gst->seek_at_nsec); 
    515525                 
    516526                if ((seek_at_sample > first_avail_sample) && (seek_at_sample < last_avail_sample)) { 
     527                        /* LOCAL seek - we have the data already ready in the ringbuffer */ 
    517528                        g_print ("seek at %ld, first %ld last %ld, LOCAL\n", seek_at_sample, first_avail_sample, last_avail_sample); 
    518529 
    519                         gint bytes_to_seek =  SAMPLES_TO_BYTES(seek_at_sample - input_gst->current_pos_samples); 
    520                         input_gst->current_pos_samples = seek_at_sample; 
     530                        gint bytes_to_seek =  SAMPLES_TO_BYTES(seek_at_sample - current_pos_samples); 
     531                        input_gst->current_pos_nsec = input_gst->seek_at_nsec; 
    521532                         
    522533                        if (bytes_to_seek > 0) { 
    523                                 jack_ringbuffer_read_advance(chk->ring, bytes_to_seek); 
     534                                jack_ringbuffer_read_advance(chk->ring, bytes_to_seek);          
    524535                        } else { 
    525536                                chk->bytes_behind_us += bytes_to_seek;  // yes, the "+" is correct 
    526537                        } 
     538                        FM_BUFFER_DISCONT (buffer) = TRUE; 
    527539                } else { 
    528540                        skip_to = _search_chunk (common, input_gst->seek_at_nsec); 
    529541                        if (skip_to) { 
     542                                /* CHUNK seek - the destination is in another ready chunk */ 
    530543                                g_print ("seek at %ld, first %ld last %ld, CHUNK %u\n", seek_at_sample, first_avail_sample, last_avail_sample, skip_to->num); 
    531544                         
    532545                        } else { 
     546                                /* FAR seek - request another ringbuffer with the destination */ 
    533547                                g_print ("seek at %ld, first %ld last %ld, FAR\n", seek_at_sample, first_avail_sample, last_avail_sample); 
    534548 
     
    552566 
    553567 
    554         /* If we have a LOCAL seek or a FAR seek is completed, skip to the new position */ 
     568        /* If a FAR seek is completed, skip to the new position */ 
    555569        if (skip_to) { 
    556570                FmChunk *old_chk = chk; 
     
    563577                chk->usable = FALSE; 
    564578                 
    565                 input_gst->current_pos_samples = ns_to_samples (common, chk->start_timestamp); 
     579                //input_gst->current_pos_samples = ns_to_samples (common, chk->start_timestamp); 
     580                input_gst->current_pos_nsec = chk->start_timestamp; 
    566581                g_print("skipping... new position = %llu\n", (long long unsigned int) chk->start_timestamp); 
    567582 
     
    570585                if (old_chk) 
    571586                        old_chk->can_destroy = TRUE; 
     587 
     588                FM_BUFFER_DISCONT (buffer) = TRUE; 
    572589        } 
    573590 
     
    583600        if ((!input_gst->play_when_ready) || (!chk) || (chk->eof)) { 
    584601                fm_buffer_fill_with_silence (buffer); 
    585                 FM_BUFFER_USED_SAMPLES (buffer) = FM_BUFFER_REQUESTED (buffer); 
    586602                return; 
    587603        } 
     
    596612     
    597613        if ((eof_samples > 0) && 
    598             ((input_gst->current_pos_samples + FM_BUFFER_REQUESTED (buffer)) > eof_samples)) 
    599                 bytes_from_ring = SAMPLES_TO_BYTES (eof_samples - input_gst->current_pos_samples); 
     614            ((current_pos_samples + FM_BUFFER_REQUESTED (buffer)) > eof_samples)) 
     615                bytes_from_ring = SAMPLES_TO_BYTES (eof_samples - current_pos_samples); 
    600616 
    601617        size_t read_bytes = jack_ringbuffer_peek(chk->ring, (gchar *) input_gst->interleaved_buffer, bytes_from_ring); 
     
    610626 
    611627        /* Timekeeping */ 
    612         FM_BUFFER_TIMESTAMP (buffer) = input_gst->current_pos_nsec; 
    613         FM_BUFFER_USED_SAMPLES(buffer) = FM_BUFFER_REQUESTED(buffer); 
    614         input_gst->current_pos_samples += BYTES_TO_SAMPLES (useful_read_bytes);  // se abbiamo un underrun durante bytes_behind_us 
    615                                                                                  // si sputtana tutto? 
    616         input_gst->current_pos_nsec = samples_to_ns (common, input_gst->current_pos_samples);  
     628        guint64 current_pos_nsec_old = input_gst->current_pos_nsec; 
     629        guint useful_read_samples = BYTES_TO_SAMPLES (useful_read_bytes); 
     630        current_pos_samples += useful_read_samples;  // se abbiamo un underrun durante bytes_behind_us si sputtana tutto? 
     631        input_gst->current_pos_nsec += samples_to_ns (common, useful_read_samples); 
     632 
     633        buffer->timestamp = current_pos_nsec_old; 
     634        buffer->used_samples = buffer->requested_samples; 
     635        buffer->duration = input_gst->current_pos_nsec - current_pos_nsec_old; 
     636        buffer->silence = FALSE; 
     637//      g_print ("DURATION %lld\n", (long long int) FM_BUFFER_DURATION (buffer)); 
     638  
    617639 
    618640 
    619641        /* Check for EOF */ 
    620         if ((eof_samples) && (input_gst->current_pos_samples >= eof_samples)) { 
    621                 g_print ("We're at %lld samples - end of file!\n", (long long int) input_gst->current_pos_samples); 
     642        if ((eof_samples) && (current_pos_samples >= eof_samples)) { 
     643                g_print ("We're at %lld samples - end of file!\n", (long long int) current_pos_samples); 
    622644                chk->eof = TRUE; 
    623645        } 
     
    745767void 
    746768fm_input_gst_seek_relative              (FmInputGst     *input_gst, 
    747                                          glong          samples) 
    748 { 
    749         g_return_if_fail(samples != 0); 
    750  
    751         glong seek_target = input_gst->current_pos_samples + samples; 
     769                                         gint64         nsec) 
     770{ 
     771        g_return_if_fail (nsec != 0); 
     772 
     773        gint64 seek_target = input_gst->current_pos_nsec + nsec; 
    752774 
    753775        if (seek_target < 0) 
    754776                seek_target = 0; 
    755777 
    756         input_gst->seek_at_nsec = samples_to_ns (input_gst->common, seek_target); 
    757 //      g_print ("samples %ld ns %lld\n", samples, (long long int) input_gst->seek_at_nsec); 
     778        input_gst->seek_at_nsec = seek_target; 
    758779} 
    759780 
     
    874895 
    875896 
    876 static void 
     897/*static void 
    877898fm_input_gst_become_sync_master         (FmElement      *element) 
    878899{ 
    879900        g_print ("FmInputGst has become sync master!\n"); 
    880901 
    881         /*sync->bpm = 120.0; 
    882         sync->beat_per_bar = 4;*/ 
    883 } 
     902}*/ 
  • fm_server/trunk/src/fm_input_gst/fm_input_gst.h

    r187 r198  
    11/* 
    22 *  FreeMix - sound server 
    3  *  Copyright (C) 2006 Alberto Botti <alberto.botti@yoda2000.net> 
     3 *  Copyright (C) 2007-2008 Alberto Botti <alberto.botti@yoda2000.net> 
    44 * 
    55 *  This program is free software; you can redistribute it and/or modify 
     
    1616 *  along with this program; if not, write to the Free Software 
    1717 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
     18 * 
     19 *  fm_input_gst.h - GStreamer input element 
    1820 */ 
    1921 
    20 #include <stdio.h> 
    2122 
    2223#define TICK_EVERY_N_SAMPLES 4000 
     
    4243        gchar           *filename; 
    4344 
    44         gint64          current_pos_samples; 
     45//      gint64          current_pos_samples; 
    4546        gint64          current_pos_nsec; 
    4647 
     
    7778void 
    7879fm_input_gst_seek_relative              (FmInputGst     *input_gst, 
    79                                          glong          samples); 
     80                                         gint64         nsec); 
    8081 
    8182void 
  • fm_server/trunk/src/fm_input_gst/fm_input_gst_common.c

    r181 r198  
     1/* 
     2 *  FreeMix - sound server 
     3 *  Copyright (C) 2007-2008 Alberto Botti <alberto.botti@yoda2000.net> 
     4 * 
     5 *  This program is free software; you can redistribute it and/or modify 
     6 *  it under the terms of the GNU General Public License as published by 
     7 *  the Free Software Foundation; either version 2 of the License, or 
     8 *  (at your option) any later version. 
     9 * 
     10 *  This program is distributed in the hope that it will be useful, 
     11 *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
     12 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     13 *  GNU Library General Public License for more details. 
     14 * 
     15 *  You should have received a copy of the GNU General Public License 
     16 *  along with this program; if not, write to the Free Software 
     17 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
     18 * 
     19 *  fm_input_gst_common.c - common data structures shared by both GstFmSink 
     20 *                          and FmInputGst 
     21 */ 
     22 
     23 
    124#include <glib.h> 
    225#include <gst/gst.h> 
  • fm_server/trunk/src/fm_input_gst/fm_input_gst_common.h

    r187 r198  
    11/* 
    22 *  FreeMix - sound server 
    3  *  Copyright (C) 2006 Alberto Botti <alberto.botti@yoda2000.net> 
     3 *  Copyright (C) 2007-2008 Alberto Botti <alberto.botti@yoda2000.net> 
    44 * 
    55 *  This program is free software; you can redistribute it and/or modify 
     
    1616 *  along with this program; if not, write to the Free Software 
    1717 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
     18 * 
     19 *  fm_input_gst_common.c - common data structures shared by both GstFmSink 
     20 *                          and FmInputGst 
    1821 */ 
    1922  
     
    4750        /* FIXME: "eof" should be moved to FmInputGst */ 
    4851        gboolean        eof;                            // the file ends somewhere in this chunk 
    49         GstClockTime    eof_timestamp;                  // where the file ends (offset from the start of the file) 
     52        GstClockTime    eof_timestamp;                  // where the file ends (stream timestamp) 
    5053        gboolean        start_of_file;                  // 1° buffer of the file 
    5154 
  • fm_server/trunk/src/fm_input_gst/gstfmsink.c

    r187 r198  
    33 * Copyright 2005 Thomas Vander Stichele <thomas@apestaart.org> 
    44 * Copyright 2005 Ronald S. Bultje <rbultje@ronald.bitfreak.net> 
    5  * Modified for FreeMix (2006) by Alberto Botti <alberto.botti@yoda2000.net> 
     5 * Modified for FreeMix (2006-2008) by Alberto Botti <alberto.botti@yoda2000.net> 
    66 *  
    77 * Permission is hereby granted, free of charge, to any person obtaining a 
     
    351351                                g_print(">   target for seek %lld, after seeking we're at %lld, skipping %lld\n",  
    352352                                        (long long int) sink->seek_target_timestamp, (long long int) timestamp, (long long int) nsec_to_skip); 
    353                                  
    354                                 chk->start_timestamp_offset += nsec_to_skip; 
    355                                 chk->bytes_behind_us = SAMPLES_TO_BYTES (ns_to_samples(common, nsec_to_skip)); 
     353 
     354                                if (nsec_to_skip < 10000000) { 
     355                         
     356                                        chk->start_timestamp_offset += nsec_to_skip; 
     357                                        chk->bytes_behind_us = SAMPLES_TO_BYTES (ns_to_samples(common, nsec_to_skip)); 
     358                                } else 
     359                                        g_warning ("too much to skip, seek failed!"); 
    356360                        } 
    357361                        sink->seek_target_timestamp = -1; 
  • fm_server/trunk/src/fm_input_gst/gstfmsink.h

    r185 r198  
    33 * Copyright 2005 Thomas Vander Stichele <thomas@apestaart.org> 
    44 * Copyright 2005 Ronald S. Bultje <rbultje@ronald.bitfreak.net> 
     5 * Modified for FreeMix (2006-2008) by Alberto Botti <alberto.botti@yoda2000.net> 
    56 *  
    67 * Permission is hereby granted, free of charge, to any person obtaining a 
     
    6566 
    6667#define SEEK_MARGIN_SAMPLES (-2000) 
    67 #define SAMPLES_FOR_SEC 44100 
     68//#define SAMPLES_FOR_SEC 44100 
     69#define SAMPLES_FOR_SEC 48000 
    6870 
    6971 
     
    7981        FmInputGstCommon *common; 
    8082 
    81         GstClockTime    start_timestamp; 
     83        GstClockTime    start_timestamp;        // ns 
    8284        gboolean        create_new_chunk; 
    8385 
    8486        gboolean        seek_in_progress;       // if TRUE, ignore "newsegment" events 
    8587        gboolean        seek_completed; 
    86         GstClockTime    seek_target_timestamp; 
     88        GstClockTime    seek_target_timestamp;  // ns 
    8789 
    8890        guint           bytes_behind_us;