- Timestamp:
- 03/01/08 22:49:03 (4 years ago)
- Location:
- trunk/fm_server/src/fm_input_gst
- Files:
-
- 6 modified
-
fm_input_gst.c (modified) (11 diffs)
-
fm_input_gst.h (modified) (1 diff)
-
fm_input_gst_common.c (modified) (2 diffs)
-
fm_input_gst_common.h (modified) (5 diffs)
-
gstfmsink.c (modified) (10 diffs)
-
gstfmsink.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/fm_server/src/fm_input_gst/fm_input_gst.c
r240 r242 259 259 const gchar *filename) 260 260 { 261 g_print("ohhhh- filename %s\n", filename);261 // g_print("ohhhh- filename %s\n", filename); 262 262 263 263 g_return_if_fail(filename); 264 264 FmElement *element = FM_ELEMENT(input_gst); 265 FmInput *input = FM_INPUT(input_gst);265 // FmInput *input = FM_INPUT(input_gst); 266 266 FmInputGstCommon *common = input_gst->common; 267 267 … … 272 272 return; 273 273 274 FmInputState prev_state = input->state; 275 276 g_print("Stopping the pipeline...\n"); 277 /* if (prev_state == FM_INPUT_PAUSE) { 278 g_print("unlocking mutex\n"); 279 common->stop_processing = TRUE; 280 fm_sem_increase (common->sem); 281 }*/ 282 283 input_gst->drop_chunks = TRUE; // let fm_input_gst_get_buffer() drop all the currently unused chunks 274 // FmInputState prev_state = input->state; 275 276 // g_print("Stopping the pipeline...\n"); 277 // input_gst->drop_chunks = TRUE; // let fm_input_gst_get_buffer() drop all the currently unused chunks 284 278 common->stop_processing = TRUE; 285 279 fm_sem_increase (common->sem); 286 gst_element_set_state (input_gst->common->pipeline, GST_STATE_ READY);280 gst_element_set_state (input_gst->common->pipeline, GST_STATE_NULL); 287 281 g_object_set (G_OBJECT (common->source), "location", input_gst->filename, NULL); 288 282 common->stop_processing = FALSE; 289 g_print("Old state was %d\n", prev_state);283 // g_print("Old state was %d\n", prev_state); 290 284 reset_status(input_gst); 291 285 … … 456 450 g_return_val_if_fail (track, NULL); 457 451 458 G List *chunk = track->chunks;452 GSList *chunk = track->chunks; 459 453 460 454 while (chunk) { 461 455 FmChunk *c = chunk->data; 462 456 463 g_print ("chunk n. %d - start %llu duration %llu", c-> num, (long long unsigned int) c->start_timestamp, (long long unsigned int) c->duration_ns);457 g_print ("chunk n. %d - start %llu duration %llu", c->id, (long long unsigned int) c->start_timestamp, (long long unsigned int) c->duration_ns); 464 458 if (c->usable) 465 459 g_print (" USABLE"); … … 472 466 (time < (c->start_timestamp + c->duration_ns))) || 473 467 ((time == 0) && (c->start_of_file))) { // see gstfmsink.c:333 474 g_print ("Found target %llu at chunk %u\n", (long long unsigned int) time, c-> num);468 g_print ("Found target %llu at chunk %u\n", (long long unsigned int) time, c->id); 475 469 return c; 476 470 } … … 488 482 g_return_if_fail (track); 489 483 490 G List *chunk_list = track->chunks;484 GSList *chunk_list = track->chunks; 491 485 492 486 while (chunk_list) { … … 495 489 496 490 if ((chunk != track->read_chunk) && (chunk->usable)) { 497 g_print ("Marking chunk %d for deletion", chunk-> num);491 g_print ("Marking chunk %d for deletion", chunk->id); 498 492 chunk->usable = FALSE; 499 493 chunk->can_destroy = TRUE; … … 524 518 /* Check if we have a new track ready */ 525 519 if (common->new_track) { 520 FmInputGstTrack *old_track = track; 526 521 input_gst->read_track = common->new_track; 527 522 track = input_gst->read_track; … … 529 524 g_print ("NEW TRACK - skipped to track %d\n", track->id); 530 525 skip_to = _search_chunk (track, 0); 526 527 if (old_track) { 528 _mark_unused_chunks_for_deletion (old_track); 529 old_track->can_destroy = TRUE; 530 } 531 531 } 532 532 … … 557 557 if (skip_to) { 558 558 /* CHUNK seek - the destination is in another ready chunk */ 559 g_print ("seek at %ld, first %ld last %ld, CHUNK %u\n", seek_at_sample, first_avail_sample, last_avail_sample, skip_to-> num);559 g_print ("seek at %ld, first %ld last %ld, CHUNK %u\n", seek_at_sample, first_avail_sample, last_avail_sample, skip_to->id); 560 560 561 561 } else { … … 606 606 607 607 /* If we are requested to drop unused chunks (ie. song change), do it now */ 608 if (input_gst->drop_chunks) {608 /*if (input_gst->drop_chunks) { 609 609 _mark_unused_chunks_for_deletion (track); 610 610 input_gst->drop_chunks = FALSE; 611 } 611 }*/ 612 612 613 613 … … 902 902 903 903 default: 904 g_print ("Got %s message\n", GST_MESSAGE_TYPE_NAME (message));904 // g_print ("Got %s message\n", GST_MESSAGE_TYPE_NAME (message)); 905 905 /* unhandled message */ 906 906 break; -
trunk/fm_server/src/fm_input_gst/fm_input_gst.h
r240 r242 53 53 guint tick_ns_count; // for "tick" 54 54 55 gboolean drop_chunks; // invalidate all the currently unused chunks55 // gboolean drop_chunks; // invalidate all the currently unused chunks 56 56 57 57 guint rt_signal; -
trunk/fm_server/src/fm_input_gst/fm_input_gst_common.c
r240 r242 30 30 31 31 FmChunk * 32 fm_chunk_new (guint samples) 32 fm_chunk_new (guint samples, 33 guint id) 33 34 { 34 35 FmChunk *chk = g_new0(FmChunk, 1); 35 36 37 chk->id = id; 36 38 chk->ring = jack_ringbuffer_create(samples * 2 * sizeof(gfloat)); 37 39 … … 53 55 FmInputGstTrack *track = g_new0(FmInputGstTrack, 1); 54 56 track->id = id; 57 track->writing = TRUE; 58 track->loaded = FALSE; 59 track->chunks = NULL; 60 track->chunk_count = 0; 61 track->write_chunk = NULL; 62 track->read_chunk = NULL; 55 63 track->gst_seek_to_ns = -1; 56 64 track->seek_waiting_for_ns = -1; -
trunk/fm_server/src/fm_input_gst/fm_input_gst_common.h
r240 r242 35 35 struct _FmChunk 36 36 { 37 guint num;37 guint id; 38 38 jack_ringbuffer_t *ring; 39 39 … … 43 43 GstClockTime start_timestamp_offset; // where to find the REAL start of the segment requested in the seek 44 44 // (as an offset from the start of the chunk) 45 GstClockTime asked_timestamp; 46 45 47 gint64 duration_ns; 46 48 … … 66 68 guint id; 67 69 68 gboolean writing; // GstFmSink can be writing to this track 69 gboolean loaded; 70 gboolean writing; // GstFmSink has write access to this track 71 // it will be set to FALSE only when it has abandoned this track 72 gboolean loaded; 73 gboolean can_destroy; // FmInputGst has stopped reading this track and moved to the next, 74 // so it can be freed 70 75 71 GList *chunks; 76 GSList *chunks; 77 guint chunk_count; 72 78 FmChunk *write_chunk; 73 79 FmChunk *read_chunk; … … 100 106 gboolean stop_processing; // discard incoming buffers and delete chunks 101 107 102 G List *tracks;108 GSList *tracks; 103 109 FmInputGstTrack *new_track; 104 110 … … 110 116 111 117 FmChunk * 112 fm_chunk_new (guint samples); 118 fm_chunk_new (guint samples, 119 guint id); 113 120 114 121 void -
trunk/fm_server/src/fm_input_gst/gstfmsink.c
r240 r242 191 191 sink->seek_target_timestamp = -1; 192 192 193 sink->chunk_count = 0;194 195 193 sink->write_track = NULL; 196 194 sink->track_count = 0; … … 234 232 gst_fm_sink_event (GstBaseSink *bsink, GstEvent *event) 235 233 { 236 g_print("> event %p (%s)\n", event, GST_EVENT_TYPE_NAME (event));234 // g_print("> event %p (%s)\n", event, GST_EVENT_TYPE_NAME (event)); 237 235 238 236 GstFmSink *sink = GST_FM_SINK (bsink); … … 252 250 } 253 251 case GST_EVENT_NEWSEGMENT: { 254 g_print("> new segment! creating a new chunk...\n");252 // g_print("> new segment! creating a new chunk...\n"); 255 253 sink->create_new_chunk = TRUE; 256 254 } … … 266 264 do_cleanup(FmInputGstTrack *track) 267 265 { 268 G List *list = track->chunks;266 GSList *list = track->chunks; 269 267 while (list) { 270 268 FmChunk *chk = (FmChunk *) list->data; 271 269 if (chk->can_destroy) { 272 track->chunks = g_ list_remove_link(track->chunks, list);270 track->chunks = g_slist_remove_link(track->chunks, list); 273 271 274 g_print("> Destroying chunk %u \n", chk->num);272 g_print("> Destroying chunk %u of track %u\n", chk->id, track->id); 275 273 fm_chunk_destroy(chk); 276 g_ list_free(list);274 g_slist_free(list); 277 275 278 276 return TRUE; 279 277 } 280 list = g_list_next(list); 278 list = g_slist_next(list); 279 } 280 281 return FALSE; 282 } 283 284 285 static gboolean 286 do_cleanup_tracks(FmInputGstCommon *common) 287 { 288 GSList *list = common->tracks; 289 while (list) { 290 FmInputGstTrack *track = (FmInputGstTrack *) list->data; 291 if (track->can_destroy) { 292 common->tracks = g_slist_remove_link(common->tracks, list); 293 294 g_print("> Destroying track %u\n", track->id); 295 while (do_cleanup(track)); // destroy the remaining unused chunks 296 297 if (g_slist_length(track->chunks) > 0) 298 g_warning ("track not empty!"); 299 300 fm_input_gst_track_destroy(track); 301 g_slist_free(list); 302 303 return TRUE; 304 } 305 list = g_slist_next(list); 281 306 } 282 307 … … 302 327 sink->seek_in_progress = FALSE; 303 328 sink->seek_target_timestamp = -1; 304 g_ print("> seek to %lld ns failed!\n", (long long int) sink->seek_target_timestamp);329 g_warning("> seek to %lld ns failed!", (long long int) sink->seek_target_timestamp); 305 330 } 306 331 … … 335 360 } 336 361 337 chk = fm_chunk_new (SAMPLES_TO_BYTES (CHUNK_SAMPLES)); 338 chk->num = sink->chunk_count++; 339 track->chunks = g_list_append (track->chunks, chk); 362 chk = fm_chunk_new (SAMPLES_TO_BYTES (CHUNK_SAMPLES), track->chunk_count++); 363 track->chunks = g_slist_append (track->chunks, chk); 340 364 track->write_chunk = chk; 341 365 342 366 gint64 timestamp = GST_BUFFER_TIMESTAMP (buf); 343 g_print ("> new chunk %d, TIMESTAMP %lld\n", chk-> num, (long long int) timestamp);367 g_print ("> new chunk %d, TIMESTAMP %lld\n", chk->id, (long long int) timestamp); 344 368 if ((timestamp > 0) && (timestamp < 50000000)) { 345 369 g_warning ("This file probably starts at timestamp %llu, taking care of it", (long long int) timestamp); … … 356 380 gint64 nsec_to_skip = sink->seek_target_timestamp - timestamp; 357 381 if (nsec_to_skip < 0) { 358 g_ print("> hell, we targeted for %lld, after seeking we're at %lld!\n",382 g_warning("> hell, we targeted for %lld, after seeking we're at %lld!", 359 383 (long long int) sink->seek_target_timestamp, (long long int) timestamp); 384 385 g_warning ("RRRREEEEETTTRRRRRRYYYY!!!!!!!!!!!!!!!!!!!!!!!!!!!! ********************************************************************************"); 386 chk->can_destroy = TRUE; 387 track->gst_seek_to_ns = sink->seek_target_timestamp; 388 389 //g_assert_not_reached (); 360 390 } else { 361 g_print("> target for seek %lld, after seeking we're at %lld, skipping %lld\n", 391 if (nsec_to_skip > 0) 392 g_warning("> target for seek %lld, after seeking we're at %lld, need to skip %lld\n", 362 393 (long long int) sink->seek_target_timestamp, (long long int) timestamp, (long long int) nsec_to_skip); 363 394 … … 397 428 if (track->gst_seek_to_ns > -1) { 398 429 if (sink->seek_in_progress) { 399 g_ print ("> seek already in progress, we'll try later\n");430 g_warning (" seek already in progress, we'll try later"); 400 431 continue; 401 432 } … … 514 545 GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS; 515 546 GstFmSink *fm_sink = GST_FM_SINK (element); 547 FmInputGstCommon *common = fm_sink->common; 516 548 517 549 switch (transition) { 518 case GST_STATE_CHANGE_READY_TO_PAUSED: { 519 g_warning ("GST_STATE_CHANGE_READY_TO_PAUSED - LOAD TRACK"); 550 case GST_STATE_CHANGE_NULL_TO_READY: { 551 g_print ("GST_STATE_CHANGE_NULL_TO_READY - LOAD TRACK\n"); 552 553 do_cleanup_tracks (common); 520 554 521 555 FmInputGstTrack *track = fm_input_gst_track_new (fm_sink->track_count++); 556 common->tracks = g_slist_append (common->tracks, track); 522 557 fm_sink->write_track = track; 523 558 track->writing = TRUE; … … 534 569 535 570 switch (transition) { 536 case GST_STATE_CHANGE_ PLAYING_TO_PAUSED:537 g_ warning ("GST_STATE_CHANGE_PLAYING_TO_PAUSED - UNLOAD TRACK");571 case GST_STATE_CHANGE_READY_TO_NULL: 572 g_print ("GST_STATE_CHANGE_READY_TO_NULL - UNLOAD TRACK\n"); 538 573 539 574 fm_sink->write_track->writing = FALSE; -
trunk/fm_server/src/fm_input_gst/gstfmsink.h
r240 r242 92 92 guint bytes_behind_us; 93 93 94 guint chunk_count;95 94 guint track_count; 96 95
