Changeset 198
- Timestamp:
- 01/16/08 13:41:11 (4 years ago)
- Location:
- fm_server/trunk/src/fm_input_gst
- Files:
-
- 6 modified
-
fm_input_gst.c (modified) (16 diffs)
-
fm_input_gst.h (modified) (4 diffs)
-
fm_input_gst_common.c (modified) (1 diff)
-
fm_input_gst_common.h (modified) (3 diffs)
-
gstfmsink.c (modified) (2 diffs)
-
gstfmsink.h (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
fm_server/trunk/src/fm_input_gst/fm_input_gst.c
r187 r198 1 1 /* 2 2 * FreeMix - sound server 3 * Copyright (C) 200 6Alberto Botti <alberto.botti@yoda2000.net>3 * Copyright (C) 2007-2008 Alberto Botti <alberto.botti@yoda2000.net> 4 4 * 5 5 * This program is free software; you can redistribute it and/or modify … … 16 16 * along with this program; if not, write to the Free Software 17 17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 * 19 * fm_input_gst.c - GStreamer input element 18 20 */ 19 21 … … 66 68 gboolean fm_input_gst_deactivate (FmElement *element); 67 69 static void fm_input_gst_get_buffer (FmElement *element, 68 FmBuffer *buffer); 70 FmBuffer *buffer, 71 FmSync *sync); 69 72 static void fm_input_gst_set_state (FmInput *input, 70 73 FmInputState new_state); … … 73 76 GstMessage *message, 74 77 gpointer data); 75 static void fm_input_gst_become_sync_master (FmElement *element);78 //static void fm_input_gst_become_sync_master (FmElement *element); 76 79 77 80 … … 150 153 element_class->deactivate = NULL; 151 154 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; 153 156 154 157 input_class->set_state = fm_input_gst_set_state; … … 178 181 { 179 182 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; 181 185 input_gst->seek_at_nsec = -1; 182 186 … … 499 503 static void 500 504 fm_input_gst_get_buffer (FmElement *element, 501 FmBuffer *buffer) 505 FmBuffer *buffer, 506 FmSync *sync) 502 507 { 503 508 FmInputGst *input_gst = FM_INPUT_GST(element); … … 507 512 508 513 514 fm_buffer_reset_flags (buffer); 515 516 guint64 current_pos_samples = ns_to_samples (common, input_gst->current_pos_nsec); 517 509 518 /* Check if we should perform a seek */ 510 519 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 513 523 514 524 guint64 seek_at_sample = ns_to_samples (common, input_gst->seek_at_nsec); 515 525 516 526 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 */ 517 528 g_print ("seek at %ld, first %ld last %ld, LOCAL\n", seek_at_sample, first_avail_sample, last_avail_sample); 518 529 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; 521 532 522 533 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); 524 535 } else { 525 536 chk->bytes_behind_us += bytes_to_seek; // yes, the "+" is correct 526 537 } 538 FM_BUFFER_DISCONT (buffer) = TRUE; 527 539 } else { 528 540 skip_to = _search_chunk (common, input_gst->seek_at_nsec); 529 541 if (skip_to) { 542 /* CHUNK seek - the destination is in another ready chunk */ 530 543 g_print ("seek at %ld, first %ld last %ld, CHUNK %u\n", seek_at_sample, first_avail_sample, last_avail_sample, skip_to->num); 531 544 532 545 } else { 546 /* FAR seek - request another ringbuffer with the destination */ 533 547 g_print ("seek at %ld, first %ld last %ld, FAR\n", seek_at_sample, first_avail_sample, last_avail_sample); 534 548 … … 552 566 553 567 554 /* If we have a LOCAL seek ora FAR seek is completed, skip to the new position */568 /* If a FAR seek is completed, skip to the new position */ 555 569 if (skip_to) { 556 570 FmChunk *old_chk = chk; … … 563 577 chk->usable = FALSE; 564 578 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; 566 581 g_print("skipping... new position = %llu\n", (long long unsigned int) chk->start_timestamp); 567 582 … … 570 585 if (old_chk) 571 586 old_chk->can_destroy = TRUE; 587 588 FM_BUFFER_DISCONT (buffer) = TRUE; 572 589 } 573 590 … … 583 600 if ((!input_gst->play_when_ready) || (!chk) || (chk->eof)) { 584 601 fm_buffer_fill_with_silence (buffer); 585 FM_BUFFER_USED_SAMPLES (buffer) = FM_BUFFER_REQUESTED (buffer);586 602 return; 587 603 } … … 596 612 597 613 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); 600 616 601 617 size_t read_bytes = jack_ringbuffer_peek(chk->ring, (gchar *) input_gst->interleaved_buffer, bytes_from_ring); … … 610 626 611 627 /* 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 617 639 618 640 619 641 /* 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); 622 644 chk->eof = TRUE; 623 645 } … … 745 767 void 746 768 fm_input_gst_seek_relative (FmInputGst *input_gst, 747 g long samples)748 { 749 g_return_if_fail (samples!= 0);750 751 g long 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; 752 774 753 775 if (seek_target < 0) 754 776 seek_target = 0; 755 777 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; 758 779 } 759 780 … … 874 895 875 896 876 static void897 /*static void 877 898 fm_input_gst_become_sync_master (FmElement *element) 878 899 { 879 900 g_print ("FmInputGst has become sync master!\n"); 880 901 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 1 1 /* 2 2 * FreeMix - sound server 3 * Copyright (C) 200 6Alberto Botti <alberto.botti@yoda2000.net>3 * Copyright (C) 2007-2008 Alberto Botti <alberto.botti@yoda2000.net> 4 4 * 5 5 * This program is free software; you can redistribute it and/or modify … … 16 16 * along with this program; if not, write to the Free Software 17 17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 * 19 * fm_input_gst.h - GStreamer input element 18 20 */ 19 21 20 #include <stdio.h>21 22 22 23 #define TICK_EVERY_N_SAMPLES 4000 … … 42 43 gchar *filename; 43 44 44 gint64 current_pos_samples;45 // gint64 current_pos_samples; 45 46 gint64 current_pos_nsec; 46 47 … … 77 78 void 78 79 fm_input_gst_seek_relative (FmInputGst *input_gst, 79 g long samples);80 gint64 nsec); 80 81 81 82 void -
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 1 24 #include <glib.h> 2 25 #include <gst/gst.h> -
fm_server/trunk/src/fm_input_gst/fm_input_gst_common.h
r187 r198 1 1 /* 2 2 * FreeMix - sound server 3 * Copyright (C) 200 6Alberto Botti <alberto.botti@yoda2000.net>3 * Copyright (C) 2007-2008 Alberto Botti <alberto.botti@yoda2000.net> 4 4 * 5 5 * This program is free software; you can redistribute it and/or modify … … 16 16 * along with this program; if not, write to the Free Software 17 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 18 21 */ 19 22 … … 47 50 /* FIXME: "eof" should be moved to FmInputGst */ 48 51 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) 50 53 gboolean start_of_file; // 1° buffer of the file 51 54 -
fm_server/trunk/src/fm_input_gst/gstfmsink.c
r187 r198 3 3 * Copyright 2005 Thomas Vander Stichele <thomas@apestaart.org> 4 4 * 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> 6 6 * 7 7 * Permission is hereby granted, free of charge, to any person obtaining a … … 351 351 g_print("> target for seek %lld, after seeking we're at %lld, skipping %lld\n", 352 352 (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!"); 356 360 } 357 361 sink->seek_target_timestamp = -1; -
fm_server/trunk/src/fm_input_gst/gstfmsink.h
r185 r198 3 3 * Copyright 2005 Thomas Vander Stichele <thomas@apestaart.org> 4 4 * Copyright 2005 Ronald S. Bultje <rbultje@ronald.bitfreak.net> 5 * Modified for FreeMix (2006-2008) by Alberto Botti <alberto.botti@yoda2000.net> 5 6 * 6 7 * Permission is hereby granted, free of charge, to any person obtaining a … … 65 66 66 67 #define SEEK_MARGIN_SAMPLES (-2000) 67 #define SAMPLES_FOR_SEC 44100 68 //#define SAMPLES_FOR_SEC 44100 69 #define SAMPLES_FOR_SEC 48000 68 70 69 71 … … 79 81 FmInputGstCommon *common; 80 82 81 GstClockTime start_timestamp; 83 GstClockTime start_timestamp; // ns 82 84 gboolean create_new_chunk; 83 85 84 86 gboolean seek_in_progress; // if TRUE, ignore "newsegment" events 85 87 gboolean seek_completed; 86 GstClockTime seek_target_timestamp; 88 GstClockTime seek_target_timestamp; // ns 87 89 88 90 guint bytes_behind_us;
