Example #1
0
/*****************************************************************************
 * vcd_Open: Opens a VCD device or file initializes, a list of
   tracks, segements and entry lsns and sizes and returns an opaque handle.
 *****************************************************************************/
static vcdinfo_obj_t *
vcd_Open( vlc_object_t *p_this, const char *psz_dev )
{
    access_t    *p_access = (access_t *)p_this;
    vcdplayer_t *p_vcdplayer    = (vcdplayer_t *) p_access->p_sys;
    vcdinfo_obj_t *p_vcdobj;
    char  *actual_dev;
    unsigned int i;

    dbg_print(INPUT_DBG_CALL, "called with %s", psz_dev);

    if( !psz_dev ) return NULL;

    actual_dev= ToLocaleDup(psz_dev);
    if( vcdinfo_open(&p_vcdobj, &actual_dev, DRIVER_UNKNOWN, NULL) !=
                                                    VCDINFO_OPEN_VCD)
    {
        free(actual_dev);
        return NULL;
    }
    free(actual_dev);

    /*
       Save summary info on tracks, segments and entries...
    */

    if ( 0 < (p_vcdplayer->i_tracks = vcdinfo_get_num_tracks(p_vcdobj)) )
    {
        p_vcdplayer->track = (vcdplayer_play_item_info_t *)
          calloc(p_vcdplayer->i_tracks, sizeof(vcdplayer_play_item_info_t));

        for (i=0; i<p_vcdplayer->i_tracks; i++)
        {
            unsigned int track_num=i+1;
            p_vcdplayer->track[i].size  =
            vcdinfo_get_track_sect_count(p_vcdobj, track_num);
            p_vcdplayer->track[i].start_LSN =
            vcdinfo_get_track_lsn(p_vcdobj, track_num);
        }
    } else
        p_vcdplayer->track = NULL;

    if( 0 < (p_vcdplayer->i_entries = vcdinfo_get_num_entries(p_vcdobj)) )
    {
        p_vcdplayer->entry = (vcdplayer_play_item_info_t *)
            calloc(p_vcdplayer->i_entries, sizeof(vcdplayer_play_item_info_t));

        for (i=0; i<p_vcdplayer->i_entries; i++)
        {
            p_vcdplayer->entry[i].size =
                                    vcdinfo_get_entry_sect_count(p_vcdobj, i);
            p_vcdplayer->entry[i].start_LSN =
                                           vcdinfo_get_entry_lsn(p_vcdobj, i);
        }
    } else
      p_vcdplayer->entry = NULL;

    if ( 0 < (p_vcdplayer->i_segments = vcdinfo_get_num_segments(p_vcdobj)) )
    {
        p_vcdplayer->segment = (vcdplayer_play_item_info_t *)
          calloc(p_vcdplayer->i_segments,  sizeof(vcdplayer_play_item_info_t));

        for (i=0; i<p_vcdplayer->i_segments; i++)
        {
            p_vcdplayer->segment[i].size =
                                    vcdinfo_get_seg_sector_count(p_vcdobj, i);
            p_vcdplayer->segment[i].start_LSN =
                                             vcdinfo_get_seg_lsn(p_vcdobj, i);
        }
    } else
      p_vcdplayer->segment = NULL;

    return p_vcdobj;
}
Example #2
0
/**
 * Once we're inside of idleproc_run(), we are executing in the context of the
 * first process-- a real context, so we can finally begin running
 * meaningful code.
 *
 * This is the body of process 0. It should initialize all that we didn't
 * already initialize in kmain(), launch the init process (initproc_run),
 * wait for the init process to exit, then halt the machine.
 *
 * @param arg1 the first argument (unused)
 * @param arg2 the second argument (unused)
 */
static void *
idleproc_run(int arg1, void *arg2)
{
        int status;
        pid_t child;


        

        /* create init proc */
        kthread_t *initthr = initproc_create();
        init_call_all();
        GDB_CALL_HOOK(initialized);

        /* Create other kernel threads (in order) */

#ifdef __VFS__
        /* Once you have VFS remember to set the current working directory
         * of the idle and init processes */
        NOT_YET_IMPLEMENTED("VFS: idleproc_run");

        /* Here you need to make the null, zero, and tty devices using mknod */
        /* You can't do this until you have VFS, check the include/drivers/dev.h
         * file for macros with the device ID's you will need to pass to mknod */
        NOT_YET_IMPLEMENTED("VFS: idleproc_run");
#endif

        /* Finally, enable interrupts (we want to make sure interrupts
         * are enabled AFTER all drivers are initialized) */
        intr_enable();

        /* Run initproc */
        sched_make_runnable(initthr);
        /* Now wait for it */
        child = do_waitpid(-1, 0, &status);
        
        KASSERT(PID_INIT == child);

#ifdef __MTP__
        kthread_reapd_shutdown();
#endif


#ifdef __SHADOWD__
        /* wait for shadowd to shutdown */
        shadowd_shutdown();
#endif

#ifdef __VFS__
        /* Shutdown the vfs: */
        dbg_print("weenix: vfs shutdown...\n");
        vput(curproc->p_cwd);
        if (vfs_shutdown())
                panic("vfs shutdown FAILED!!\n");

#endif

        /* Shutdown the pframe system */
#ifdef __S5FS__
        pframe_shutdown();
#endif

        dbg_print("\nweenix: halted cleanly!\n");
        GDB_CALL_HOOK(shutdown);
        hard_shutdown();
        return NULL;
}
Example #3
0
/****************************************************************************
 * VCDSeek
 ****************************************************************************/
int
VCDSeek( access_t * p_access, uint64_t i_pos )
{
    if (!p_access || !p_access->p_sys) return VLC_EGENERIC;
    {
        vcdplayer_t         *p_vcdplayer = (vcdplayer_t *)p_vcd_access->p_sys;
        unsigned int         i_entry = VCDINFO_INVALID_ENTRY;

        /* Next sector to read */
        p_vcdplayer->i_lsn = (i_pos / (uint64_t) M2F2_SECTOR_SIZE) +
                             p_vcdplayer->origin_lsn;

        switch (p_vcdplayer->play_item.type)
        {
        case VCDINFO_ITEM_TYPE_TRACK:
        case VCDINFO_ITEM_TYPE_ENTRY:
            break;
        default:
            p_vcdplayer->b_valid_ep = false;
            break;
        }

        /* Find entry */
        if( p_vcdplayer->b_valid_ep )
        {
            for( i_entry = 0 ; i_entry < p_vcdplayer->i_entries ; i_entry ++ )
            {
                if( p_vcdplayer->i_lsn < p_vcdplayer->p_entries[i_entry] )
                {
                    VCDUpdateVar( p_access, i_entry, VLC_VAR_SETVALUE,
                                  "chapter", _("Entry"), "Setting entry" );
                    break;
                }
            }

            {
                vcdinfo_itemid_t itemid;
                itemid.num  = i_entry;
                itemid.type = VCDINFO_ITEM_TYPE_ENTRY;
                VCDSetOrigin(p_access, p_vcdplayer->i_lsn,
                             p_vcdplayer->i_track, &itemid);
            }
        }

        dbg_print( (INPUT_DBG_CALL|INPUT_DBG_EXT|INPUT_DBG_SEEK),
                   "orig %lu, cur: %lu, offset: %"PRIi64", entry %d",
                   (long unsigned int) p_vcdplayer->origin_lsn,
                   (long unsigned int) p_vcdplayer->i_lsn, i_pos,
                   i_entry );
#if 0
        /* Find seekpoint */
        const input_title_t *t = p_vcdplayer->p_title[p_vcdplayer->i_cur_title];
        int i_seekpoint;

        for( i_seekpoint = 0; i_seekpoint < t->i_seekpoint; i_seekpoint++ )
        {
            if( i_seekpoint + 1 >= t->i_seekpoint ) break;

            if( i_pos < t->seekpoint[i_seekpoint + 1]->i_byte_offset ) break;
        }
 
        /* Update current seekpoint */
        if( p_vcdplayer->i_cur_chapter != i_seekpoint )
            dbg_print( (INPUT_DBG_SEEK), "seekpoint change %d",
                       i_seekpoint );
        p_vcdplayer->i_cur_chapter = i_seekpoint;
#endif
    }
    p_access->info.b_eof = false;
    return VLC_SUCCESS;
}
Example #4
0
extern void mate_analyze_frame(packet_info *pinfo, proto_tree* tree) {
    mate_cfg_pdu* cfg;
    GPtrArray* protos;
    field_info* proto;
    guint i,j;
    AVPL* criterium_match;

    mate_pdu* pdu = NULL;
    mate_pdu* last = NULL;

    rd->now = (float) nstime_to_sec(&pinfo->fd->rel_ts);

    if ( proto_tracking_interesting_fields(tree)
            && rd->highest_analyzed_frame < pinfo->fd->num ) {
        for ( i = 0; i < mc->pducfglist->len; i++ ) {

            cfg = (mate_cfg_pdu *)g_ptr_array_index(mc->pducfglist,i);

            dbg_print (dbg_pdu,4,dbg_facility,"mate_analyze_frame: trying to extract: %s",cfg->name);
            protos = proto_get_finfo_ptr_array(tree, cfg->hfid_proto);

            if (protos)  {
                pdu = NULL;

                for (j = 0; j < protos->len; j++) {

                    dbg_print (dbg_pdu,3,dbg_facility,"mate_analyze_frame: found matching proto, extracting: %s",cfg->name);

                    proto = (field_info*) g_ptr_array_index(protos,j);
                    pdu = new_pdu(cfg, pinfo->fd->num, proto, tree);

                    if (cfg->criterium) {
                        criterium_match = new_avpl_from_match(cfg->criterium_match_mode,"",pdu->avpl,cfg->criterium,FALSE);

                        if (criterium_match) {
                            delete_avpl(criterium_match,FALSE);
                        }

                        if ( (criterium_match && cfg->criterium_accept_mode == REJECT_MODE )
                                || ( ! criterium_match && cfg->criterium_accept_mode == ACCEPT_MODE )) {

                            delete_avpl(pdu->avpl,TRUE);
                            g_slice_free(mate_max_size,(mate_max_size*)pdu);
                            pdu = NULL;

                            continue;
                        }
                    }

                    analyze_pdu(pdu);

                    if ( ! pdu->gop && cfg->drop_unassigned) {
                        delete_avpl(pdu->avpl,TRUE);
                        g_slice_free(mate_max_size,(mate_max_size*)pdu);
                        pdu = NULL;
                        continue;
                    }

                    if ( cfg->discard ) {
                        delete_avpl(pdu->avpl,TRUE);
                        pdu->avpl = NULL;
                    }

                    if (!last) {
                        g_hash_table_insert(rd->frames,GINT_TO_POINTER(pinfo->fd->num),pdu);
                        last = pdu;
                    } else {
                        last->next_in_frame = pdu;
                        last = pdu;
                    }

                }

                if ( pdu && cfg->last_extracted ) break;
            }
        }

        rd->highest_analyzed_frame = pinfo->fd->num;
    }
}
H264_DPB_entry* open_api_h264_get_empty_dpb(void)
{
    kal_uint32 index, i, Ind;
    kal_int32 minPOC;
    H264_DPB_entry *p_DPB = NULL, *dpbe;

    /*Scott, Check if there is any free dpb be marked as un-used for ref. in the ref marking process */
    open_api_h264_check_free_dpb();

    // check fullness
    if (g_open_api_h264_DPB_list.num_used == (g_open_api_h264_dec_info_ptr->dec_param.max_DPB_number+1))
    {
        //Needs to do bumping process here!!
        // Find the removable entry with minimal POC
        minPOC = (kal_int32)maxINT;
        Ind = 0;
        dpbe = g_open_api_h264_DPB_list.dpbe;
        for (i=0; i < (g_open_api_h264_dec_info_ptr->dec_param.max_DPB_number+1);  i++)// find the one with smallest POC
        {
            p_DPB = dpbe++;
            if ( (p_DPB->isOutputed == 1) && (p_DPB->status_marked == H264_unused_ref) )
            {
                if (p_DPB->POC < minPOC)
                {
                    minPOC = p_DPB->POC;
					Ind = i;
				}
			}
		}
		if (minPOC != maxINT)
		{
			p_DPB = &g_open_api_h264_DPB_list.dpbe[Ind];
			//clear_rpe_by_ind(dpbe->statusMarked, Ind);
			open_api_h264_free_dpb(p_DPB);
			g_open_api_h264_DPB_list.num_used--;
			//return p_DPB;		// Move to the final
			goto GET_EMPTY_END;
		}

        // In the non-display-ordering mode, if goes here there must be something wrong...
        //
        if (fgDisplayOrderMode == KAL_FALSE)
        {
            //ASSERT(0);
            return NULL;
        }

		// Find non-outputed one with smallest POC and do bumping process.
		while (1)
		{
			minPOC = get_ind_dpbe_with_smallest_poc(&Ind);
			if (minPOC == maxINT)
			{
				video_dbg_trace(H264_DEC_FIND_SMALLEST_POC_FAIL, 0);
				dbg_print("[DRV H264]get_ind_dpbe_with_smallest_poc fails\n\r");
				return NULL;
			}

			p_DPB = &g_open_api_h264_DPB_list.dpbe[Ind];
			if (p_DPB->isOutputed == 0) 
			{
				p_DPB->isOutputed = 1;
				if (output_a_pic_normal(p_DPB) != 1)
				{
					video_dbg_trace(H264_DEC_OUTPUT_PIC_FAIL, p_DPB->frame_no);
					dbg_print("[DRV H264]output_a_pic_normal() fails, frames_no = %d\n\r", p_DPB->frame_no);
					return NULL;
				}
			}

			video_dbg_trace(H264_DEC_BUMPING_PROCESS, p_DPB->frame_no);
			dbg_print("[DRV H264]open_api_h264_get_empty_dpb() DPB Full, Bumping process remove frame: %d\n\r", p_DPB->frame_no);
			if (p_DPB->status_marked == H264_unused_ref)
			{
				open_api_h264_free_dpb(p_DPB);
				g_open_api_h264_DPB_list.num_used--;
				//return p_DPB;		// Move to the final
				break;
			}
		}
	}

	GET_EMPTY_END: 
	for (index=0; index < (g_open_api_h264_dec_info_ptr->dec_param.max_DPB_number+1); index++)
	{
		if (g_open_api_h264_DPB_list.dpbe[index].b_used == KAL_FALSE)
		{
			g_open_api_h264_DPB_list.dpbe[index].b_used = KAL_TRUE;
			p_DPB = &g_open_api_h264_DPB_list.dpbe[index];
			g_open_api_h264_DPB_list.num_used++;
			break;
		}
	}

	return p_DPB;
}
Example #6
0
static void reanalyze_gop(mate_gop* gop) {
    LoAL* gog_keys = NULL;
    AVPL* curr_gogkey = NULL;
    mate_cfg_gop* gop_cfg = NULL;
    void* cookie = NULL;
    AVPL* gogkey_match = NULL;
    mate_gog* gog = gop->gog;
    gogkey* gog_key;

    if ( ! gog ) return;

    gog->last_time = rd->now;

    dbg_print (dbg_gog,1,dbg_facility,"reanalyze_gop: %s:%d",gop->cfg->name,gop->id);

    apply_extras(gop->avpl,gog->avpl,gog->cfg->extra);

    /* XXX: Instead of using the length of the avpl to check if an avpl has changed,
    		which is not accurate at all,  we should have apply_extras,
    		apply_transformations and other functions that can modify the avpl
    	    to flag the avpl if it has changed, then we'll check for the flag
    	    and clear it after analysis */

    if (gog->last_n != gog->avpl->len) {

        dbg_print (dbg_gog,2,dbg_facility,"reanalyze_gop: gog has new attributes let's look for new keys");

        gog_keys = gog->cfg->keys;

        while (( curr_gogkey = get_next_avpl(gog_keys,&cookie) )) {
            gop_cfg = (mate_cfg_gop *)g_hash_table_lookup(mc->gopcfgs,curr_gogkey->name);

            if (( gogkey_match = new_avpl_exact_match(gop_cfg->name,gog->avpl,curr_gogkey,FALSE) )) {

                gog_key = (gogkey *)g_malloc(sizeof(gogkey));

                gog_key->key = avpl_to_str(gogkey_match);
                delete_avpl(gogkey_match,FALSE);

                gog_key->cfg = gop_cfg;

                if (g_hash_table_lookup(gop_cfg->gog_index,gog_key->key)) {
                    g_free(gog_key->key);
                    g_free(gog_key);
                    gog_key = NULL;
                }

                if (! gog_key ) {
                    /* XXX: since these gogs actually share key info
                    		we should try to merge (non released) gogs
                            that happen to have equal keys */
                } else {
                    dbg_print (dbg_gog,1,dbg_facility,"analyze_gop: new key for gog=%s:%d : %s",gog->cfg->name,gog->id,gog_key->key);
                    g_ptr_array_add(gog->gog_keys,gog_key);
                    g_hash_table_insert(gog_key->cfg->gog_index,gog_key->key,gog);
                }

            }
        }

        gog->last_n = gog->avpl->len;
    }

    if (gog->num_of_released_gops == gog->num_of_counting_gops) {
        gog->released =  TRUE;
        gog->expiration = gog->cfg->expiration + rd->now;
    } else {
        gog->released =  FALSE;
    }
}
Example #7
0
static void analyze_pdu(mate_pdu* pdu) {
    /* TODO:
    return a g_boolean to tell we've destroyed the pdu when the pdu is unnassigned
    destroy the unassigned pdu
    */
    mate_cfg_gop* cfg = NULL;
    mate_gop* gop = NULL;
    gchar* gop_key;
    gchar* orig_gop_key = NULL;
    AVPL* candidate_start = NULL;
    AVPL* candidate_stop = NULL;
    AVPL* is_start = NULL;
    AVPL* is_stop = NULL;
    AVPL* gopkey_match = NULL;
    LoAL* gog_keys = NULL;
    AVPL* curr_gogkey = NULL;
    void* cookie = NULL;
    AVPL* gogkey_match = NULL;
    gchar* gogkey_str = NULL;

    dbg_print (dbg_gop,1,dbg_facility,"analyze_pdu: %s",pdu->cfg->name);

    if (! (cfg = (mate_cfg_gop *)g_hash_table_lookup(mc->gops_by_pduname,pdu->cfg->name)) )
        return;

    if ((gopkey_match = new_avpl_exact_match("gop_key_match",pdu->avpl,cfg->key, TRUE))) {
        gop_key = avpl_to_str(gopkey_match);

        g_hash_table_lookup_extended(cfg->gop_index,(gconstpointer)gop_key,(gpointer *)&orig_gop_key,(gpointer *)&gop);

        if ( gop ) {
            g_free(gop_key);

            /* is the gop dead ? */
            if ( ! gop->released &&
                    ( ( gop->cfg->lifetime > 0.0 && gop->time_to_die >= rd->now) ||
                      ( gop->cfg->idle_timeout > 0.0 && gop->time_to_timeout >= rd->now) ) ) {
                dbg_print (dbg_gop,4,dbg_facility,"analyze_pdu: expiring released gop");
                gop->released = TRUE;

                if (gop->gog && gop->cfg->start) gop->gog->num_of_released_gops++;
            }

            /* TODO: is the gop expired? */

            gop_key = orig_gop_key;

            dbg_print (dbg_gop,2,dbg_facility,"analyze_pdu: got gop: %s",gop_key);

            if (( candidate_start = cfg->start )) {

                dbg_print (dbg_gop,2,dbg_facility,"analyze_pdu: got candidate start");

                if (( is_start = new_avpl_exact_match("",pdu->avpl, candidate_start, FALSE) )) {
                    delete_avpl(is_start,FALSE);
                    if ( gop->released ) {
                        dbg_print (dbg_gop,3,dbg_facility,"analyze_pdu: start on released gop, let's create a new gop");

                        g_hash_table_remove(cfg->gop_index,gop_key);
                        gop->gop_key = NULL;
                        gop = new_gop(cfg,pdu,gop_key);
                        g_hash_table_insert(cfg->gop_index,gop_key,gop);
                    } else {
                        dbg_print (dbg_gop,1,dbg_facility,"analyze_pdu: duplicate start on gop");
                    }
                }
            }

            pdu->gop = gop;

            if (gop->last_pdu) gop->last_pdu->next = pdu;
            gop->last_pdu = pdu;
            pdu->next = NULL;
            pdu->time_in_gop = rd->now - gop->start_time;

            if (gop->released) pdu->after_release = TRUE;

        } else {

            dbg_print (dbg_gop,1,dbg_facility,"analyze_pdu: no gop already");

            if ( ! cfg->start ) {
                /* there is no GopStart, we'll check for matching GogKeys
                if we have one we'll create the Gop */

                apply_extras(pdu->avpl,gopkey_match,cfg->extra);

                gog_keys = (LoAL *)g_hash_table_lookup(mc->gogs_by_gopname,cfg->name);

                if (gog_keys) {

                    while (( curr_gogkey = get_next_avpl(gog_keys,&cookie) )) {
                        if (( gogkey_match = new_avpl_exact_match(cfg->name,gopkey_match,curr_gogkey,FALSE) )) {
                            gogkey_str = avpl_to_str(gogkey_match);

                            if (g_hash_table_lookup(cfg->gog_index,gogkey_str)) {
                                gop = new_gop(cfg,pdu,gop_key);
                                g_hash_table_insert(cfg->gop_index,gop_key,gop);
                                delete_avpl(gogkey_match,FALSE);
                                g_free(gogkey_str);
                                break;
                            } else {
                                delete_avpl(gogkey_match,FALSE);
                                g_free(gogkey_str);
                            }
                        }
                    }

                    if ( ! gop ) {
                        g_free(gop_key);
                        delete_avpl(gopkey_match,TRUE);
                        return;
                    }

                } else {
                    g_free(gop_key);
                    delete_avpl(gopkey_match,TRUE);
                    return;
                }

            } else {
                candidate_start = cfg->start;

                if (( is_start = new_avpl_exact_match("",pdu->avpl, candidate_start, FALSE) )) {
                    delete_avpl(is_start,FALSE);
                    gop = new_gop(cfg,pdu,gop_key);
                } else {
                    g_free(gop_key);
                    return;
                }

                pdu->gop = gop;
            }
        }

        if (gop->last_pdu) gop->last_pdu->next = pdu;
        gop->last_pdu = pdu;
        pdu->next = NULL;

        pdu->time_in_gop = rd->now - gop->start_time;

        gop->num_of_pdus++;
        gop->time_to_timeout = cfg->idle_timeout > 0.0 ? cfg->idle_timeout + rd->now : (float) -1.0 ;

        dbg_print (dbg_gop,4,dbg_facility,"analyze_pdu: merge with key");

        merge_avpl(gop->avpl,gopkey_match,TRUE);
        delete_avpl(gopkey_match,TRUE);

        dbg_print (dbg_gop,4,dbg_facility,"analyze_pdu: apply extras");

        apply_extras(pdu->avpl,gop->avpl,gop->cfg->extra);

        gop->last_time = pdu->rel_time;

        if ( ! gop->released) {
            candidate_stop = cfg->stop;

            if (candidate_stop) {
                is_stop = new_avpl_exact_match("",pdu->avpl, candidate_stop,FALSE);
            } else {
                is_stop = new_avpl("");
            }

            if(is_stop) {
                dbg_print (dbg_gop,1,dbg_facility,"analyze_pdu: is a `stop");
                delete_avpl(is_stop,FALSE);

                if (! gop->released) {
                    gop->released = TRUE;
                    gop->release_time = pdu->rel_time;
                    if (gop->gog && gop->cfg->start) gop->gog->num_of_released_gops++;
                }

                pdu->is_stop = TRUE;

            }
        }

        if (gop->last_n != gop->avpl->len) apply_transforms(gop->cfg->transforms,gop->avpl);

        gop->last_n = gop->avpl->len;

        if (gop->gog) {
            reanalyze_gop(gop);
        } else {
            analyze_gop(gop);
        }

    } else {
        dbg_print (dbg_gop,4,dbg_facility,"analyze_pdu: no match for this pdu");

        pdu->gop = NULL;
    }
}
Example #8
0
/**
 * new_avpl_loose_match:
 * @name: the name of the resulting avpl
 * @src: avpl to be matched agains an "op" avpl
 * @op: the "op" avpl that will be matched against the src avpl
 * @copy_avps: whether the avps in the resulting avpl should be copied
 *
 * creates an avp list containing any avps in src matching any avps in op
 * it will eventually create an empty list in none match
 *
 * Return value: a pointer to the newly created avpl containing the
 *				 matching avps.
 **/
extern AVPL* new_avpl_loose_match(const gchar* name,
								  AVPL* src,
								  AVPL* op,
								  gboolean copy_avps) {

	AVPL* newavpl = new_avpl(scs_subscribe(avp_strings, name));
	AVPN* co = NULL;
	AVPN* cs = NULL;
	ptrdiff_t c;
	AVP* m;
	AVP* copy;

#ifdef _AVP_DEBUGGING
	dbg_print(dbg_avpl_op,3,dbg_fp,"new_avpl_loose_match: %X src=%X op=%X name='%s'",newavpl,src,op,name);
#endif


	cs = src->null.next;
	co = op->null.next;
	while(1) {

		if (!co->avp) {
			return newavpl;
		}

		if (!cs->avp) {
			return newavpl;
		}


		c = ADDRDIFF(co->avp->n, cs->avp->n);

		if ( c > 0 ) {
			if (co->avp) co = co->next;
		} else if (c < 0) {
			if (cs->avp) cs = cs->next;
		} else {
			m = match_avp(cs->avp,co->avp);
			if(m) {

				if (copy_avps) {
					copy = avp_copy(m);
					if ( ! insert_avp(newavpl,copy) ) {
						delete_avp(copy);
					}
				} else {
					insert_avp(newavpl,m);
				}


			}

			if (cs->avp) cs = cs->next;

		}
	}

#ifdef _AVP_DEBUGGING
	dbg_print(dbg_avpl_op,6,dbg_fp,"new_avpl_loose_match: done!");
#endif

	return NULL;
}
void write_cc_line_as_transcript2(struct eia608_screen *data, struct encoder_ctx *context, int line_number)
{
	unsigned h1,m1,s1,ms1;
	unsigned h2,m2,s2,ms2;
	LLONG start_time = data->start_time;
	LLONG end_time = data->end_time;
	if (ccx_options.sentence_cap)
	{
		capitalize (line_number,data);
		correct_case(line_number,data);
	}
	int length = get_decoder_line_basic (subline, line_number, data,ccx_options.trim_subs,ccx_options.encoding);
	if (ccx_options.encoding!=CCX_ENC_UNICODE)
	{
		dbg_print(CCX_DMT_DECODER_608, "\r");
		dbg_print(CCX_DMT_DECODER_608, "%s\n",subline);
	}
	if (length>0)
	{
		if (data->start_time == -1)
		{
			// CFS: Means that the line has characters but we don't have a timestamp for the first one. Since the timestamp
			// is set for example by the write_char function, it possible that we don't have one in empty lines (unclear)
			// For now, let's not consider this a bug as before and just return.
			// fatal (EXIT_BUG_BUG, "Bug in timedtranscript (ts_start_of_current_line==-1). Please report.");
			return;
		}

		if (ccx_options.transcript_settings.showStartTime){
			char buf1[80];
			if (ccx_options.transcript_settings.relativeTimestamp){
				millis_to_date(start_time + context->subs_delay, buf1);
				fdprintf(context->out->fh, "%s|", buf1);
			}
			else {
				mstotime(start_time + context->subs_delay, &h1, &m1, &s1, &ms1);
				time_t start_time_int = (start_time + context->subs_delay) / 1000;
				int start_time_dec = (start_time + context->subs_delay) % 1000;
				struct tm *start_time_struct = gmtime(&start_time_int);
				strftime(buf1, sizeof(buf1), "%Y%m%d%H%M%S", start_time_struct);
				fdprintf(context->out->fh, "%s%c%03d|", buf1,ccx_options.millis_separator,start_time_dec);
			}
		}

		if (ccx_options.transcript_settings.showEndTime){
			char buf2[80];
			if (ccx_options.transcript_settings.relativeTimestamp){
				millis_to_date(end_time, buf2);
				fdprintf(context->out->fh, "%s|", buf2);
			}
			else {
				mstotime(get_fts() + context->subs_delay, &h2, &m2, &s2, &ms2);
				time_t end_time_int = (end_time + context->subs_delay) / 1000;
				int end_time_dec = (end_time + context->subs_delay) % 1000;
				struct tm *end_time_struct = gmtime(&end_time_int);
				strftime(buf2, sizeof(buf2), "%Y%m%d%H%M%S", end_time_struct);
				fdprintf(context->out->fh, "%s%c%03d|", buf2,ccx_options.millis_separator,end_time_dec);
			}
		}

		if (ccx_options.transcript_settings.showCC){
			fdprintf(context->out->fh, "CC%d|", data->my_field == 1 ? data->channel : data->channel + 2); // Data from field 2 is CC3 or 4
		}
		if (ccx_options.transcript_settings.showMode){
			const char *mode = "???";
			switch (data->mode)
			{
			case MODE_POPON:
				mode = "POP";
				break;
			case MODE_FAKE_ROLLUP_1:
				mode = "RU1";
				break;
			case MODE_ROLLUP_2:
				mode = "RU2";
				break;
			case MODE_ROLLUP_3:
				mode = "RU3";
				break;
			case MODE_ROLLUP_4:
				mode = "RU4";
				break;
			case MODE_TEXT:
				mode = "TXT";
				break;
			case MODE_PAINTON:
				mode = "PAI";
				break;
			}
			fdprintf(context->out->fh, "%s|", mode);
		}

		write(context->out->fh, subline, length);
		write(context->out->fh, encoded_crlf, encoded_crlf_length);
	}
	// fprintf (wb->fh,encoded_crlf);
}
Example #10
0
/**
 * new_avpl_exact_match:
 * @name: the name of the resulting avpl
 * @src: avpl to be matched agains an "op" avpl
 * @op: the "op" avpl that will be matched against the src avpl
 * @copy_avps: whether the avps in the resulting avpl should be copied
 *
 * creates an avp list containing every avp in src matching every avp in op
 * it will not create a list unless every avp in op is matched only once
 * to every avp in op.
 *
 * Return value: a pointer to the newly created avpl containing the
 *				 matching avps.
 **/
extern AVPL* new_avpl_exact_match(const gchar* name,AVPL* src, AVPL* op, gboolean copy_avps) {
	AVPL* newavpl = new_avpl(name);
	AVPN* co = NULL;
	AVPN* cs = NULL;
	ptrdiff_t c;
	AVP* m;
	AVP* copy;

#ifdef _AVP_DEBUGGING
	dbg_print(dbg_avpl_op,3,dbg_fp,"new_avpl_every_match: %X src=%X op=%X name='%s'",newavpl,src,op,name);
#endif

	if (op->len == 0)
		return newavpl;

	if (src->len == 0) {
		delete_avpl(newavpl,FALSE);
		return NULL;
	}

	cs = src->null.next;
	co = op->null.next;
	while(1) {

		c = ADDRDIFF(co->avp->n,cs->avp->n);

		if ( c > 0 ) {
			delete_avpl(newavpl,TRUE);
			return NULL;
		} else if (c < 0) {
			cs = cs->next;
			if (! cs->avp ) {
				delete_avpl(newavpl,TRUE);
				return NULL;
			}
		} else {
			m = match_avp(cs->avp,co->avp);

			if(m) {
				cs = cs->next;
				co = co->next;

				if (copy_avps) {
					copy = avp_copy(m);
					if ( ! insert_avp(newavpl,copy) ) {
						delete_avp(copy);
					}
				} else {
					insert_avp(newavpl,m);
				}


				if (!co->avp) {
					return newavpl;
				}
				if (!cs->avp) {
					delete_avpl(newavpl,TRUE);
					return NULL;
				}
			} else {
				delete_avpl(newavpl,TRUE);
				return NULL;
			}
		}

	}

	/* should never be reached */
	return NULL;
}
Example #11
0
/**
* match_avp:
 * @src: an src to be compared agains an "op" avp
 * @op: the "op" avp that will be matched against the src avp
 *
 * Checks whether or not two avp's match.
 *
 * Return value: a pointer to the src avp if there's a match.
 *
 **/
extern AVP* match_avp(AVP* src, AVP* op) {
	gchar** splited;
	int i;
	gchar* p;
	guint ls;
	guint lo;
	float fs = 0.0f;
	float fo = 0.0f;
	gboolean lower = FALSE;

#ifdef _AVP_DEBUGGING
	dbg_print(dbg_avpl_op,3,dbg_fp,"match_avp: %s%c%s; vs. %s%c%s;",src->n,src->o,src->v,op->n,op->o,op->v);
#endif

	if ( src->n != op->n ) {
		return NULL;
	}

	switch (op->o) {
		case AVP_OP_EXISTS:
			return src;
		case AVP_OP_EQUAL:
			return src->v == op->v ? src : NULL;
		case AVP_OP_NOTEQUAL:
			return !( src->v == op->v) ? src : NULL;
		case AVP_OP_STARTS:
			return strncmp(src->v,op->v,strlen(op->v)) == 0 ? src : NULL;
		case AVP_OP_ONEOFF:
			splited = g_strsplit(op->v,"|",0);
			if (splited) {
				for (i=0;splited[i];i++) {
					if(g_str_equal(splited[i],src->v)) {
						g_strfreev(splited);
						return src;
					}
				}
				g_strfreev(splited);
			}
			return NULL;

		case AVP_OP_LOWER:
			lower = TRUE;
			/* FALLTHRU */
		case AVP_OP_HIGHER:

			fs = (float) g_ascii_strtod(src->v, NULL);
			fo = (float) g_ascii_strtod(op->v, NULL);

			if (lower) {
				if (fs<fo) return src;
				else return NULL;
			} else {
				if (fs>fo) return src;
				else return NULL;
			}
		case AVP_OP_ENDS:
			/* does this work? */
			ls = (guint) strlen(src->v);
			lo = (guint) strlen(op->v);

			if ( ls < lo ) {
				return NULL;
			} else {
				p = src->v + ( ls - lo );
				return g_str_equal(p,op->v) ? src : NULL;
			}

		/* case AVP_OP_TRANSF: */
		/*	return do_transform(src,op); */
		case AVP_OP_CONTAINS:
			/* TODO */
			return NULL;
	}
	/* will never get here */
	return NULL;
}
Example #12
0
/**
* new_avpl_every_match:
 * @name: the name of the resulting avpl
 * @src: avpl to be matched agains an "op" avpl
 * @op: the "op" avpl that will be matched against the src avpl
 * @copy_avps: whether the avps in the resulting avpl should be copied
 *
 * creates an avp list containing any avps in src matching every avp in op
 * it will not create a list if there is not a match for every attribute in op
 *
 * Return value: a pointer to the newly created avpl containing the
 *				 matching avps.
 **/
extern AVPL* new_avpl_every_match(const gchar* name, AVPL* src, AVPL* op, gboolean copy_avps) {
	AVPL* newavpl;
	AVPN* co = NULL;
	AVPN* cs = NULL;
	ptrdiff_t c;
	AVP* m;
	AVP* copy;
	gboolean matches;

#ifdef _AVP_DEBUGGING
	dbg_print(dbg_avpl_op,3,dbg_fp,"new_avpl_every_match: %X src=%X op=%X name='%s'",newavpl,src,op,name);
#endif
	if (src->len == 0) return NULL;

	newavpl = new_avpl(scs_subscribe(avp_strings, name));

	if (op->len == 0)
		return newavpl;

	matches = TRUE;

	cs = src->null.next;
	co = op->null.next;
	while(1) {

		if (!co->avp) {
			break;
		}

		if (!cs->avp) {
			break;
		}

		c = ADDRDIFF(co->avp->n,cs->avp->n);

		if ( c > 0 ) {
			delete_avpl(newavpl,TRUE);
			return NULL;
		} else if (c < 0) {
			cs = cs->next;
			if (! cs->avp ) {
				break;
			}
		} else {
			m = match_avp(cs->avp,co->avp);

			if(m) {
				matches++;
				cs = cs->next;
				co = co->next;

				if (copy_avps) {
					copy = avp_copy(m);
					if ( ! insert_avp(newavpl,copy) ) {
						delete_avp(copy);
					}
				} else {
					insert_avp(newavpl,m);
				}

			} else {
				cs = cs->next;
			}
		}

	}

	if (matches) {
		return newavpl;
	} else {
		delete_avpl(newavpl,TRUE);
		return NULL;
	}
}
Example #13
0
static block_t *Reassemble( decoder_t *p_dec, block_t *p_block )
{
    decoder_sys_t *p_sys = p_dec->p_sys;
    uint8_t *p_buffer;
    uint16_t i_expected_image;
    uint8_t  i_packet, i_expected_packet;

    if( p_block->i_flags & (BLOCK_FLAG_DISCONTINUITY|BLOCK_FLAG_CORRUPTED) )
    {
        block_Release( p_block );
        return NULL;
    }

    if( p_block->i_buffer < SPU_HEADER_LEN )
    {
        msg_Dbg( p_dec, "invalid packet header (size %zu < %u)" ,
                 p_block->i_buffer, SPU_HEADER_LEN );
        block_Release( p_block );
        return NULL;
    }

    p_buffer = p_block->p_buffer;

    if( p_sys->i_state == SUBTITLE_BLOCK_EMPTY )
    {
        i_expected_image  = p_sys->i_image + 1;
        i_expected_packet = 0;
    }
    else
    {
        i_expected_image  = p_sys->i_image;
        i_expected_packet = p_sys->i_packet + 1;
    }

    /* The dummy ES that the menu selection uses has an 0x70 at
       the head which we need to strip off. */
    p_buffer += 2;

    if( *p_buffer & 0x80 )
    {
        p_sys->i_state = SUBTITLE_BLOCK_COMPLETE;
        i_packet       = *p_buffer++ & 0x7F;
    }
    else
    {
        p_sys->i_state = SUBTITLE_BLOCK_PARTIAL;
        i_packet       = *p_buffer++;
    }

    p_sys->i_image = GETINT16(p_buffer);

    if( p_sys->i_image != i_expected_image )
    {
        msg_Warn( p_dec, "expected subtitle image %u but found %u",
                  i_expected_image, p_sys->i_image );
    }

    if( i_packet != i_expected_packet )
    {
        msg_Warn( p_dec, "expected subtitle image packet %u but found %u",
                  i_expected_packet, i_packet );
    }

    p_block->p_buffer += SPU_HEADER_LEN;
    p_block->i_buffer -= SPU_HEADER_LEN;

    p_sys->i_packet = i_packet;
    /* First packet in the subtitle block */
    if( !p_sys->i_packet ) ParseHeader( p_dec, p_block );

    block_ChainAppend( &p_sys->p_spu, p_block );

    if( p_sys->i_state == SUBTITLE_BLOCK_COMPLETE )
    {
        block_t *p_spu = block_ChainGather( p_sys->p_spu );

        if( p_spu->i_buffer != p_sys->i_spu_size )
        {
            msg_Warn( p_dec, "subtitle packets size=%zu should be %zu",
                      p_spu->i_buffer, p_sys->i_spu_size );
        }

        dbg_print( (DECODE_DBG_PACKET),
                   "subtitle packet complete, size=%zu", p_spu->i_buffer );

        p_sys->i_state = SUBTITLE_BLOCK_EMPTY;
        p_sys->p_spu = 0;
        return p_spu;
    }

    return NULL;
}
Example #14
0
/*****************************************************************************
  VCDOpen: open VCD.
  read in meta-information about VCD: the number of tracks, segments,
  entries, size and starting information. Then set up state variables so
  that we read/seek starting at the location specified.

  On success we return VLC_SUCCESS, on memory exhausted VLC_ENOMEM,
  and VLC_EGENERIC for some other error.
 *****************************************************************************/
int
VCDOpen ( vlc_object_t *p_this )
{
    access_t         *p_access = (access_t *)p_this;
    vcdplayer_t      *p_vcdplayer;
    char             *psz_source;
    vcdinfo_itemid_t  itemid;
    bool        play_single_item = false;

    p_access->pf_read          = NULL;
    p_access->pf_block         = VCDReadBlock;
    p_access->pf_control       = VCDControl;
    p_access->pf_seek          = VCDSeek;

    p_access->info.i_pos       = 0;
    p_access->info.b_eof       = false;

    p_vcdplayer = malloc( sizeof(vcdplayer_t) );

    if( p_vcdplayer == NULL )
        return VLC_ENOMEM;

    p_vcdplayer->i_debug = var_InheritInteger( p_this, MODULE_STRING "-debug" );
    p_access->p_sys = (access_sys_t *) p_vcdplayer;
    p_vcdplayer->size = 0;

    /* Set where to log errors messages from libcdio. */
    p_vcd_access = p_access;
    cdio_log_set_handler ( cdio_log_handler );
    vcd_log_set_handler ( vcd_log_handler );

    psz_source = VCDParse( p_access, &itemid, &play_single_item );

    if ( NULL == psz_source )
    {
        free( p_vcdplayer );
        return( VLC_EGENERIC );
    }

    dbg_print( (INPUT_DBG_CALL|INPUT_DBG_EXT), "source: %s: mrl: %s",
               psz_source, p_access->psz_location );

    p_vcdplayer->psz_source        = strdup(psz_source);
    p_vcdplayer->i_blocks_per_read = var_InheritInteger( p_this, MODULE_STRING
                                                    "-blocks-per-read" );
    p_vcdplayer->b_track_length    = var_InheritInteger( p_this, MODULE_STRING
                                                    "-track-length" );
    p_vcdplayer->in_still          = false;
    p_vcdplayer->play_item.type    = VCDINFO_ITEM_TYPE_NOTFOUND;
    p_vcdplayer->p_input           = p_access->p_input;
//    p_vcdplayer->p_meta            = vlc_meta_New();
    p_vcdplayer->p_segments        = NULL;
    p_vcdplayer->p_entries         = NULL;
    p_vcdplayer->i_cur_title       = 0;
    p_vcdplayer->i_cur_chapter     = 0;

    /* set up input  */

    if( !(p_vcdplayer->vcd = vcd_Open( p_this, psz_source )) )
    {
        goto err_exit;
    }

    p_vcdplayer->b_svd = vcdinfo_get_tracksSVD(p_vcdplayer->vcd);

    /* Get track information. */
    p_vcdplayer->i_tracks = vcdinfo_get_num_tracks(p_vcdplayer->vcd);

    if( p_vcdplayer->i_tracks<1 || CDIO_INVALID_TRACK==p_vcdplayer->i_tracks )
    {
        vcdinfo_close( p_vcdplayer->vcd );
        LOG_ERR ("no movie tracks found" );
        goto err_exit;
    }

    /* Build Navigation Title table for the tracks. */
    VCDTitles( p_access );

    /* Add into the above entry points as "Chapters". */
    if( ! VCDEntryPoints( p_access ) )
    {
        msg_Warn( p_access, "could not read entry points, will not use them" );
        p_vcdplayer->b_valid_ep = false;
    }

    /* Initialize LID info and add that as a menu item */
    if( ! VCDLIDs( p_access ) )
    {
        msg_Warn( p_access, "could not read entry LIDs" );
    }

    /* Do we set PBC (via LID) on? */
    p_vcdplayer->i_lid =
      ( VCDINFO_ITEM_TYPE_LID == itemid.type
        && p_vcdplayer->i_lids > itemid.num )
      ? itemid.num
      :  VCDINFO_INVALID_ENTRY;

    /* Initialize segment information and add that a "Track". */
    VCDSegments( p_access );

    vcdplayer_play( p_access, itemid );

#ifdef FIXED
    if( play_single_item )
        VCDFixupPlayList(p_access,p_vcd,psz_source,&itemid,play_single_item);
#endif

    p_vcdplayer->p_access = p_access;

    free( psz_source );

    return VLC_SUCCESS;
 err_exit:
    free( psz_source );
    free( p_vcdplayer->psz_source );
    free( p_vcdplayer );
    return VLC_EGENERIC;
}
Example #15
0
File: dawm.c Project: dstenb/dawm
void
handler_expose(XEvent *ev)
{
	(void)ev;
	dbg_print(__func__);
}
Example #16
0
// Read ts packets until a complete video PES element can be returned.
// The data is read into capbuf and the function returns the number of
// bytes read.
long ts_readstream(void)
{
    static int prev_ccounter = 0;
    static int prev_packet = 0;
    int gotpes = 0;
    long pespcount=0; // count packets in PES with captions
    long pcount=0; // count all packets until PES is complete
    int saw_pesstart = 0;
	
    capbuflen = 0;

    do
    {
        pcount++;

        if( !prev_packet )
        {
            // Exit the loop at EOF
            if ( !ts_readpacket() )
                break;
        }
        else
            prev_packet = 0;

		// Skip damaged packets, they could do more harm than good
		if (payload.transport_error)
		{
			dbg_print(DMT_VERBOSE, "Packet (pid %u) skipped - transport error.\n",
				payload.pid);
            continue;
		}
        // Skip packets with no payload.  This also fixes the problems
        // with the continuity counter not being incremented in empty
        // packets.		
        if ( !payload.length )
        {
			dbg_print(DMT_VERBOSE, "Packet (pid %u) skipped - no payload.\n",
				payload.pid);
            continue;
        }
		
		if (cappid == 0) 
		{
            if (!payload.pesstart)
                // Not the first entry. Ignore it, it should not be here.
                continue;
		}

        // Check for PAT
        if( payload.pid == 0 && telext_mode!=TXT_IN_USE) // If teletext is in use, then we don't need to process PAT
        {
            if (!payload.pesstart)
                // Not the first entry. Ignore it, it should not be here.
                continue;

            unsigned pointer_field = *(payload.start);
            unsigned char *payload_start = payload.start + pointer_field + 1;
            unsigned payload_length = tspacket+188-payload_start;

            unsigned table_id = payload_start[0];
            unsigned section_length = (((payload_start[1] & 0x0F) << 8)
                                       | payload_start[2]);
            unsigned transport_stream_id = ((payload_start[3] << 8)
                                            | payload_start[4]);
            unsigned version_number = (payload_start[5] & 0x3E) >> 1;
            unsigned current_next_indicator = payload_start[5] & 0x01;
            unsigned section_number = payload_start[6];
            unsigned last_section_number = payload_start[7];
            if ( last_section_number > 0 )
            {
                fatal(EXIT_BUG_BUG,
                      "Sorry, long PATs not yet supported!\n");
            }

            if (!current_next_indicator)
                // This table is not active, no need to evaluate
                continue;

            payload_start += 8;
            payload_length = tspacket+188-payload_start;

            unsigned programm_data = section_length - 5 - 4; // prev. bytes and CRC

            dbg_print(DMT_PARSE, "Read PAT packet (id: %u) ts-id: 0x%04x\n",
                   table_id, transport_stream_id);
            dbg_print(DMT_PARSE, "  section length: %u  number: %u  last: %u\n",
                   section_length, section_number, last_section_number);
            dbg_print(DMT_PARSE, "  version_number: %u  current_next_indicator: %u\n",
                   version_number, current_next_indicator);

            if ( programm_data+4 > payload_length )
            {
                fatal(EXIT_BUG_BUG,
                      "Sorry, PAT too long!\n");
            }

            unsigned ts_prog_num = 0;
            unsigned ts_prog_map_pid = 0;
            dbg_print(DMT_VERBOSE, "\nProgram association section (PAT)\n");
            for( unsigned i=0; i < programm_data; i+=4)
            {
                unsigned program_number = ((payload_start[i] << 8)
                                           | payload_start[i+1]);
                unsigned prog_map_pid = ((payload_start[i+2] << 8)
                                         | payload_start[i+3]) & 0x1FFF;

                dbg_print(DMT_VERBOSE, "  Program number: %u  -> PMTPID: %u\n",
                            program_number, prog_map_pid);

                if( program_number != 0 )
                {
                    if ( ts_prog_num && ts_prog_num!=program_number && !ts_forced_program_selected)
					{
                        // We can only work with "simple" ts files
						mprint ("\nThis TS file has more than one program. These are the program numbers found: \n");
						for( unsigned j=0; j < programm_data; j+=4)
						{
							unsigned pn = ((payload_start[j] << 8)
                                           | payload_start[j+1]);
							if (pn)
								mprint ("%u\n",pn);
							activity_program_number (pn);
						}
                        fatal(EXIT_BUG_BUG, "Run ccextractor again with --program-number specifying which program to process.");
					}
                    else
					{
                        if (!ts_forced_program_selected || program_number == ts_forced_program)
						{
							// Otherwise ignore
							ts_prog_num = program_number;
							ts_prog_map_pid = prog_map_pid;
						}
					}
                }
            }

            // If we found a new PAT reset all TS stream variables
            if( ts_prog_num != TS_program_number )
            {
                TS_program_number = ts_prog_num;
                pmtpid = ts_prog_map_pid;
                cappid = 0; // Reset caption stream pid
                // If we have data flush it
                if( capbuflen > 0 )
                {
                    gotpes = 1;
                    break;
                }
            }
            continue;
        }

        // PID != 0 but no PMT defined yet, ignore the rest of the current
        // package and continue searching.
        if ( !pmtpid && telext_mode!=TXT_IN_USE)
        {
            dbg_print(DMT_PARSE, "Packet (pid %u) skipped - no PMT pid identified yet.\n",
                       payload.pid);
            continue;
        }

        // Check for PMT (ISO13818-1 / table 2-28)
        if( payload.pid == pmtpid && telext_mode!=TXT_IN_USE)
        {
            if (!payload.pesstart)
                // Not the first entry. Ignore it, it should not be here.
                continue;

            unsigned pointer_field = *(payload.start);
            unsigned char *payload_start = payload.start + pointer_field + 1;
            unsigned payload_length = tspacket+188-payload_start;

            unsigned table_id = payload_start[0];
            unsigned section_length = (((payload_start[1] & 0x0F) << 8)
                                       | payload_start[2]);
            unsigned program_number = ((payload_start[3] << 8)
                                       | payload_start[4]);
            if (program_number != TS_program_number)
            {
                // Only use PMTs with matching program number
				dbg_print(DMT_PARSE,"Reject this PMT packet (pid: %u) program number: %u\n",
                           pmtpid, program_number);
                
                continue;
            }

            unsigned version_number = (payload_start[5] & 0x3E) >> 1;
            unsigned current_next_indicator = payload_start[5] & 0x01;
            if (!current_next_indicator)
                // This table is not active, no need to evaluate
                continue;
            unsigned section_number = payload_start[6];
            unsigned last_section_number = payload_start[7];
            if ( last_section_number > 0 )
            {
                mprint("Long PMTs are not supported - reject!\n");
                continue;
            }
            unsigned PCR_PID = (((payload_start[8] & 0x1F) << 8)
                                | payload_start[9]);
            unsigned pi_length = (((payload_start[10] & 0x0F) << 8)
                                  | payload_start[11]);

            if( 12 + pi_length >  payload_length )
            {
                // If we would support long PMTs, this would be wrong.
                mprint("program_info_length cannot be longer than the payload_length - reject!\n");
                continue;
            }
            payload_start += 12 + pi_length;
            payload_length = tspacket+188-payload_start;

            unsigned stream_data = section_length - 9 - pi_length - 4; // prev. bytes and CRC

            dbg_print(DMT_PARSE, "Read PMT packet  (id: %u) program number: %u\n",
                   table_id, program_number);
            dbg_print(DMT_PARSE, "  section length: %u  number: %u  last: %u\n",
                   section_length, section_number, last_section_number);
            dbg_print(DMT_PARSE, "  version_number: %u  current_next_indicator: %u\n",
                   version_number, current_next_indicator);
            dbg_print(DMT_PARSE, "  PCR_PID: %u  data length: %u  payload_length: %u\n",
                   PCR_PID, stream_data, payload_length);

            if ( stream_data+4 > payload_length )
            {
                fatal(EXIT_BUG_BUG,
                      "Sorry, PMT to long!\n");
            }

            unsigned newcappid = 0;
            unsigned newcap_stream_type = 0;
            dbg_print(DMT_VERBOSE, "\nProgram map section (PMT)\n");

            for( unsigned i=0; i < stream_data; i+=5)
            {
                unsigned stream_type = payload_start[i];
                unsigned elementary_PID = (((payload_start[i+1] & 0x1F) << 8)
                                           | payload_start[i+2]);
                unsigned ES_info_length = (((payload_start[i+3] & 0x0F) << 8)
                                           | payload_start[i+4]);

				if (telext_mode==TXT_AUTO_NOT_YET_FOUND && stream_type == PRIVATE_MPEG2) // MPEG-2 Packetized Elementary Stream packets containing private data
				{
					// descriptor_tag: 0x45 = VBI_data_descriptor, 0x46 = VBI_teletext_descriptor, 0x56 = teletext_descriptor
					unsigned descriptor_tag = payload_start[i + 5];
					if ((descriptor_tag == 0x45) || (descriptor_tag == 0x46) || (descriptor_tag == 0x56))
					{
						telxcc_init();
						cappid = newcappid = elementary_PID;
						cap_stream_type = newcap_stream_type = stream_type;
						telext_mode =TXT_IN_USE;						
						mprint ("VBI/teletext stream ID %u (0x%x) for SID %u (0x%x)\n",
							elementary_PID, elementary_PID, program_number, program_number);
					}
				}
                // For the print command below
                unsigned tmp_stream_type = stream_type;
                switch (stream_type)
                {
                case VIDEO_MPEG2:
                case VIDEO_H264:
					// If telext has been detected/selected it has priority over video for subtitles
					if (telext_mode != TXT_IN_USE)
					{
						newcappid = elementary_PID;
						newcap_stream_type = stream_type;
					}
                    break;
				case PRIVATE_MPEG2:
                case VIDEO_MPEG1:
                case AUDIO_MPEG1:
                case AUDIO_MPEG2:
                case AUDIO_AAC:
                case VIDEO_MPEG4:
                case AUDIO_AC3:
                case AUDIO_DTS:
                case AUDIO_HDMV_DTS:
                    break;
                default:
                    tmp_stream_type = UNKNOWNSTREAM;
                    break;
                }
                dbg_print(DMT_VERBOSE, "  %s stream [0x%02x]  -  PID: %u\n",
                        desc[tmp_stream_type],
                        stream_type, elementary_PID);
                i += ES_info_length;
            }
            if (!newcappid)
            {
                mprint("No supported stream with caption data found - reject!\n");
                continue;
            }
            if (newcappid != cappid)
            {
                cappid = newcappid;
                cap_stream_type = newcap_stream_type;
                mprint ("Decode captions from %s stream [0x%02x]  -  PID: %u\n",
                        desc[cap_stream_type], cap_stream_type, cappid);
                // If we have data flush it
                if( capbuflen > 0 )
                {
                    gotpes = 1;
                    break;
                }
            }
            continue;
        }
		if (PIDs_seen[payload.pid] == 0)
		{
			mprint ("\nNew PID found: %u\n", payload.pid);
			PIDs_seen[payload.pid] = 1;
		}
		if (payload.pid==1003 && !hauppauge_warning_shown && !hauppauge_mode) 
		{
			// TODO: Change this very weak test for something more decent such as size.
			mprint ("\n\nNote: This TS could be a recording from a Hauppage card. If no captions are detected, try --hauppauge\n\n");
			hauppauge_warning_shown=1;
		}

        // No caption stream PID defined yet, continue searching.
        if ( !cappid )
        {
            dbg_print(DMT_PARSE, "Packet (pid %u) skipped - no stream with captions identified yet.\n",
                       payload.pid);
            continue;
        }

		if (hauppauge_mode && payload.pid==HAUPPAGE_CCPID)
		{
			// Haup packets processed separately, because we can't mix payloads. So they go in their own buffer
            // copy payload to capbuf
            int haup_newcapbuflen = haup_capbuflen + payload.length;
            if ( haup_newcapbuflen > haup_capbufsize) {
                haup_capbuf = (unsigned char*)realloc(haup_capbuf, haup_newcapbuflen);
                if (!haup_capbuf)
                    fatal(EXIT_NOT_ENOUGH_MEMORY, "Out of memory");
                haup_capbufsize = haup_newcapbuflen;
            }
            memcpy(haup_capbuf+haup_capbuflen, payload.start, payload.length);
            haup_capbuflen = haup_newcapbuflen;

		}

        // Check for PID with captions. Note that in Hauppauge mode we also process the video stream because
		// we need the timing from its PES header, which isn't included in Hauppauge's packets
		// CFS: Warning. Most likely mixing payloads.
		if( payload.pid == cappid)
        {   // Now we got a payload

            // Video PES start
            if (payload.pesstart)
            {
                // Pretend the previous was smaller
                prev_ccounter=payload.counter-1;

                saw_pesstart = 1;
            }

			// Discard packets when no pesstart was found.
            if ( !saw_pesstart )
            {
                dbg_print(DMT_PARSE, "Packet (pid %u) skipped - Did not see pesstart.\n",
                           payload.pid);
                continue;
            }

            // If the buffer is empty we just started this function
            if (payload.pesstart && capbuflen > 0)
            {
                dbg_print(DMT_PARSE, "\nPES finished (%ld bytes/%ld PES packets/%ld total packets)\n",
                           capbuflen, pespcount, pcount);
			
                // Keep the data in capbuf to be worked on

                prev_packet = 1;
                gotpes = 1;
                break;
            }

            if ( (prev_ccounter==15 ? 0 : prev_ccounter+1) != payload.counter )
            {
                mprint("TS continuity counter not incremented prev/curr %u/%u\n",
                       prev_ccounter, payload.counter);
            }
            prev_ccounter = payload.counter;


            pespcount++;
            // copy payload to capbuf
            int newcapbuflen = capbuflen + payload.length;
            if ( newcapbuflen > capbufsize) {
                capbuf = (unsigned char*)realloc(capbuf, newcapbuflen);
                if (!capbuf)
                    fatal(EXIT_NOT_ENOUGH_MEMORY, "Out of memory");
                capbufsize = newcapbuflen;
            }
            memcpy(capbuf+capbuflen, payload.start, payload.length);
            capbuflen = newcapbuflen;
        }
        //else
        //    if(debug_verbose)
        //        printf("Packet (pid %u) skipped - unused.\n",
        //               payload.pid);

        // Nothing suitable found, start over
    }
    while( !gotpes ); // gotpes==1 never arrives here because of the breaks

    return capbuflen;
}
Example #17
0
File: dawm.c Project: dstenb/dawm
void
handler_mappingnotify(XEvent *ev)
{
	(void)ev;
	dbg_print(__func__);
}
Example #18
0
// Return 1 for sucessfully read ts packet
int ts_readpacket(void)
{
    buffered_read(tspacket,188);
    past+=result;
    if (result!=188)
    {
        if (result>0)
            mprint("Premature end of file!\n");
        end_of_file=1;
        return 0;
    }

    int printtsprob = 1;
    while (tspacket[0]!=0x47)
    {
        if (printtsprob)
        {
            mprint ("\nProblem: No TS header mark. Received bytes:\n");
            dump (DMT_GENERIC_NOTICES, tspacket,4, 0, 0);

            mprint ("Skip forward to the next TS header mark.\n");
            printtsprob = 0;
        }

        unsigned char *tstemp;
        // The amount of bytes read into tspacket
        int tslen = 188;

        // Check for 0x47 in the remaining bytes of tspacket
        tstemp = (unsigned char *) memchr (tspacket+1, 0x47, tslen-1);
        if (tstemp != NULL )
        {
            // Found it
            int atpos = tstemp-tspacket;

            memmove (tspacket,tstemp,(size_t)(tslen-atpos));
            buffered_read(tspacket+(tslen-atpos),atpos);
            past+=result;
            if (result!=atpos) 
            {
                mprint("Premature end of file!\n");
                end_of_file=1;
                return 0;
            }
        }
        else
        {
            // Read the next 188 bytes.
            buffered_read(tspacket,tslen);
            past+=result;
            if (result!=tslen) 
            {
                mprint("Premature end of file!\n");
                end_of_file=1;
                return 0;
            }
        }
    }

    unsigned char *payload_start = tspacket + 4;
    unsigned payload_length = 188 - 4;

    unsigned transport_error_indicator = (tspacket[1]&0x80)>>7;
    unsigned payload_start_indicator = (tspacket[1]&0x40)>>6;
    // unsigned transport_priority = (tspacket[1]&0x20)>>5;
    unsigned pid = (((tspacket[1] & 0x1F) << 8) | tspacket[2]) & 0x1FFF;
    // unsigned transport_scrambling_control = (tspacket[3]&0xC0)>>6;
    unsigned adaptation_field_control = (tspacket[3]&0x30)>>4;
    unsigned ccounter = tspacket[3] & 0xF;

    if (transport_error_indicator)
    {
        mprint ("Warning: Defective (error indicator on) TS packet:\n");
        dump (DMT_GENERIC_NOTICES, tspacket, 188, 0, 0);
    }

    unsigned adaptation_field_length = 0;
    if ( adaptation_field_control & 2 )
    {
		// TODO: If present, we should take the PCR (Program Clock Reference) from here, in case PTS is not
		// available, as done in telxcc.
        adaptation_field_length = tspacket[4];

        payload_start = payload_start + adaptation_field_length + 1;
        payload_length = tspacket+188-payload_start;
    }

    dbg_print(DMT_PARSE, "TS pid: %d  PES start: %d  counter: %u  payload length: %u  adapt length: %d\n",
            pid, payload_start_indicator, ccounter, payload_length,
            int(adaptation_field_length));

    // Catch bad packages with adaptation_field_length > 184 and
    // the unsigned nature of payload_length leading to huge numbers.
    if (payload_length > 184)
    {
        // This renders the package invalid
        payload_length = 0;
        dbg_print(DMT_PARSE, "  Reject package - set length to zero.\n");
    }

    // Save data in global struct
    payload.start = payload_start;
    payload.length = payload_length;
    payload.pesstart = payload_start_indicator;
    payload.pid = pid;
    payload.counter = ccounter;
	payload.transport_error = transport_error_indicator;
    if (payload_length == 0)
    {
        dbg_print(DMT_PARSE, "  No payload in package.\n");
    }

    // Store packet information
    return 1;
}
Example #19
0
static void analyze_gop(mate_gop* gop) {
    mate_cfg_gog* cfg = NULL;
    LoAL* gog_keys = NULL;
    AVPL* curr_gogkey = NULL;
    void* cookie = NULL;
    AVPL* gogkey_match = NULL;
    mate_gog* gog = NULL;
    gchar* key = NULL;

    if ( ! gop->gog  ) {
        /* no gog, let's either find one or create it if due */
        dbg_print (dbg_gog,1,dbg_facility,"analyze_gop: no gog");

        gog_keys = (LoAL *)g_hash_table_lookup(mc->gogs_by_gopname,gop->cfg->name);

        if ( ! gog_keys ) {
            dbg_print (dbg_gog,1,dbg_facility,"analyze_gop: no gog_keys for this gop");
            return;
        }

        /* We have gog_keys! look for matching gogkeys */

        dbg_print (dbg_gog,1,dbg_facility,"analyze_gop: got gog_keys: %s",gog_keys->name) ;

        while (( curr_gogkey = get_next_avpl(gog_keys,&cookie) )) {
            if (( gogkey_match = new_avpl_exact_match(gop->cfg->name,gop->avpl,curr_gogkey,TRUE) )) {

                key = avpl_to_str(gogkey_match);

                dbg_print (dbg_gog,1,dbg_facility,"analyze_gop: got gogkey_match: %s",key);

                if (( gog = (mate_gog *)g_hash_table_lookup(gop->cfg->gog_index,key) )) {
                    dbg_print (dbg_gog,1,dbg_facility,"analyze_gop: got already a matching gog");

                    if (gog->num_of_counting_gops == gog->num_of_released_gops && gog->expiration < rd->now) {
                        dbg_print (dbg_gog,1,dbg_facility,"analyze_gop: this is a new gog, not the old one, let's create it");

                        gog_remove_keys(gog);

                        new_gog(gog->cfg,gop);

                        break;
                    } else {
                        dbg_print (dbg_gog,1,dbg_facility,"analyze_gop: this is our gog");

                        if (! gop->gog ) adopt_gop(gog,gop);

                        break;
                    }
                } else {
                    dbg_print (dbg_gog,1,dbg_facility,"analyze_gop: no such gog in hash, let's create a new %s",curr_gogkey->name);

                    cfg = (mate_cfg_gog *)g_hash_table_lookup(mc->gogcfgs,curr_gogkey->name);

                    if (cfg) {
                        gog = new_gog(cfg,gop);
                        gog->num_of_gops = 1;

                        if (gop->cfg->start) {
                            gog->num_of_counting_gops = 1;
                        }

                    } else {
                        dbg_print (dbg_gog,0,dbg_facility,"analyze_gop: no such gog_cfg: %s",curr_gogkey->name);
                    }

                    break;
                }

                /** Can't get here because of "breaks" above */
                g_assert_not_reached();
            }

            dbg_print (dbg_gog,1,dbg_facility,"analyze_gop: no gogkey_match: %s",key);
        } /* while */

        g_free(key);
        key = NULL;

        if (gogkey_match) delete_avpl(gogkey_match,TRUE);

        reanalyze_gop(gop);
    }
}
Example #20
0
// TS specific data grabber
LLONG ts_getmoredata(void)
{
    long payload_read = 0;
    const char *tstr; // Temporary string to describe the stream type
	
    do
    {
        if( !ts_readstream() )
        {   // If we didn't get data, try again
            mprint("empty\n");
            continue;
        }

        // Separate MPEG-2 and H.264 video streams
        if( cap_stream_type == VIDEO_MPEG2)
        {
            bufferdatatype = PES;
            tstr = "MPG";
        }
        else if( cap_stream_type == VIDEO_H264 )
        {
            bufferdatatype = H264;
            tstr = "H.264";
        }
		else if ( cap_stream_type == UNKNOWNSTREAM && hauppauge_mode)
		{
            bufferdatatype = HAUPPAGE;
            tstr = "Hauppage";
		}
		else if ( cap_stream_type == PRIVATE_MPEG2 && telext_mode==TXT_IN_USE)
		{
            bufferdatatype = TELETEXT;
            tstr = "Teletext";
		}
		else
            fatal(EXIT_BUG_BUG,
                  "Not reachable!");

        // We read a video PES

        if (capbuf[0]!=0x00 || capbuf[1]!=0x00 ||
            capbuf[2]!=0x01)
        {
            // ??? Shouldn't happen. Complain and try again.
            mprint("Missing PES header!\n");
            dump(DMT_GENERIC_NOTICES, capbuf,256, 0, 0);
            continue;
        }
        unsigned stream_id = capbuf[3];

		if (telext_mode == TXT_IN_USE)
		{
			if (cappid==0)
			{ // If here, the user forced teletext mode but didn't supply a PID, and we haven't found it yet.
				continue;
			}			
			memcpy(buffer+inbuf, capbuf, capbuflen);
			payload_read = capbuflen;		
			inbuf += capbuflen;
			break;						
		}
		if (hauppauge_mode)
		{
			if (haup_capbuflen%12 != 0)			
				mprint ("Warning: Inconsistent Hauppage's buffer length\n");
			if (!haup_capbuflen)
			{
				// Do this so that we always return something until EOF. This will be skipped.
				buffer[inbuf++]=0xFA; 
				buffer[inbuf++]=0x80;
				buffer[inbuf++]=0x80;
				payload_read+=3;
			}

			for (int i=0; i<haup_capbuflen; i+=12)
			{
				unsigned haup_stream_id = haup_capbuf[i+3];
				if (haup_stream_id==0xbd && haup_capbuf[i+4]==0 && haup_capbuf[i+5]==6 )
				{
				// Because I (CFS) don't have a lot of samples for this, for now I make sure everything is like the one I have:
				// 12 bytes total length, stream id = 0xbd (Private non-video and non-audio), etc
					if (2 > BUFSIZE - inbuf) 
					{
						fatal(EXIT_BUG_BUG,
							"Remaining buffer (%lld) not enough to hold the 3 Hauppage bytes.\n"
							"Please send bug report!",
							BUFSIZE - inbuf);
					}				
					if (haup_capbuf[i+9]==1 || haup_capbuf[i+9]==2) // Field match. // TODO: If extract==12 this won't work!
					{
						if (haup_capbuf[i+9]==1)
							buffer[inbuf++]=4; // Field 1 + cc_valid=1
						else
							buffer[inbuf++]=5; // Field 2 + cc_valid=1
						buffer[inbuf++]=haup_capbuf[i+10];
						buffer[inbuf++]=haup_capbuf[i+11];			
						payload_read+=3;						
					}							
					/*
					if (inbuf>1024) // Just a way to send the bytes to the decoder from time to time, otherwise the buffer will fill up.
						break;		
					else
						continue; */
				}
			}
			haup_capbuflen=0;			
		}

		if( !((stream_id&0xf0)==0xe0)) // 0xBD = private stream
        {
            // ??? Shouldn't happen. Complain and try again.
            mprint("Not a video PES header!\n");
            continue;
        }

        dbg_print(DMT_VERBOSE, "TS payload start video PES id: %d  len: %ld\n",
               stream_id, capbuflen);

        int pesheaderlen;
        int vpesdatalen = read_video_pes_header(capbuf, &pesheaderlen, capbuflen);

        if (vpesdatalen < 0)
        {   // Seems to be a broken PES
            end_of_file=1;
            break;
        }

        unsigned char *databuf = capbuf + pesheaderlen;
        long databuflen = capbuflen - pesheaderlen;

        // If the package length is unknown vpesdatalen is zero.
        // If we know he package length, use it to quit
        dbg_print(DMT_VERBOSE, "Read PES-%s (databuffer %ld/PES data %d) ",
               tstr, databuflen, vpesdatalen);
        // We got the whole PES in buffer
        if( vpesdatalen && (databuflen >= vpesdatalen) )
            dbg_print(DMT_VERBOSE, " - complete");
        dbg_print(DMT_VERBOSE, "\n");
        

        if (databuflen > BUFSIZE - inbuf)
        {
            fatal(EXIT_BUG_BUG,
                  "PES data packet (%ld) larger than remaining buffer (%lld).\n"
                  "Please send bug report!",
                   databuflen, BUFSIZE - inbuf);
        }

		if (!hauppauge_mode) // in Haup mode the buffer is filled somewhere else
		{
			memcpy(buffer+inbuf, databuf, databuflen);
			payload_read = databuflen;		
			inbuf += databuflen;
		}
        break;
    }
    while ( !end_of_file );

    return payload_read;
}
Example #21
0
static mate_pdu* new_pdu(mate_cfg_pdu* cfg, guint32 framenum, field_info* proto, proto_tree* tree) {
    mate_pdu* pdu = (mate_pdu*)g_slice_new(mate_max_size);
    field_info* cfi;
    GPtrArray* ptrs;
    mate_range* range;
    mate_range* proto_range;
    tmp_pdu_data data;
    guint i,j;
    gint min_dist;
    field_info* range_fi;
    gint32 last_start;
    gint32 first_end;
    gint32 curr_end;
    int hfid;

    dbg_print (dbg_pdu,1,dbg_facility,"new_pdu: type=%s framenum=%i",cfg->name,framenum);

    pdu->id = ++(cfg->last_id);
    pdu->cfg = cfg;

    pdu->avpl = new_avpl(cfg->name);

    pdu->frame = framenum;
    pdu->next_in_frame = NULL;
    pdu->rel_time = rd->now;

    pdu->gop = NULL;
    pdu->next = NULL;
    pdu->time_in_gop = -1.0f;

    pdu->first = FALSE;
    pdu->is_start = FALSE;
    pdu->is_stop = FALSE;
    pdu->after_release = FALSE;

    data.ranges = g_ptr_array_new();
    data.pdu  = pdu;
    data.tree = tree;

    /* first we create the proto range */
    proto_range = (mate_range *)g_malloc(sizeof(mate_range));
    proto_range->start = proto->start;
    proto_range->end = proto->start + proto->length;
    g_ptr_array_add(data.ranges,proto_range);

    dbg_print(dbg_pdu,3,dbg_facility,"new_pdu: proto range %u-%u",proto_range->start,proto_range->end);

    last_start = proto_range->start;

    /* we move forward in the tranport */
    for (i = cfg->transport_ranges->len; i--; ) {
        hfid = *((int*)g_ptr_array_index(cfg->transport_ranges,i));
        ptrs = proto_get_finfo_ptr_array(tree, hfid);
        min_dist = 99999;
        range_fi = NULL;

        if (ptrs) {
            for (j=0; j < ptrs->len; j++) {
                cfi = (field_info*) g_ptr_array_index(ptrs,j);
                if (cfi->start < last_start && min_dist >= (last_start - cfi->start) ) {
                    range_fi = cfi;
                    min_dist = last_start - cfi->start;
                }
            }

            if ( range_fi ) {
                range = (mate_range *)g_malloc(sizeof(*range));
                range->start = range_fi->start;
                range->end = range_fi->start + range_fi->length;
                g_ptr_array_add(data.ranges,range);

                last_start = range_fi->start;

                dbg_print(dbg_pdu,3,dbg_facility,"new_pdu: transport(%i) range %i-%i",hfid,range->start,range->end);
            } else {
                /* we missed a range  */
                dbg_print(dbg_pdu,6,dbg_facility,"new_pdu: transport(%i) missed",hfid);
            }

        }
    }

    if (cfg->payload_ranges) {

        first_end = proto_range->end;

        for (i = 0 ; i < cfg->payload_ranges->len; i++) {
            hfid = *((int*)g_ptr_array_index(cfg->payload_ranges,i));
            ptrs = proto_get_finfo_ptr_array(tree, hfid);
            min_dist = 99999;
            range_fi = NULL;

            if (ptrs) {
                for (j=0; j < ptrs->len; j++) {
                    cfi = (field_info*) g_ptr_array_index(ptrs,j);
                    curr_end = cfi->start + cfi->length;
                    if (curr_end > first_end && min_dist >= (curr_end - first_end) ) {
                        range_fi = cfi;
                        min_dist = curr_end - first_end;
                    }
                }

                if ( range_fi ) {
                    range = (mate_range *)g_malloc(sizeof(*range));
                    range->start = range_fi->start;
                    range->end = range_fi->start + range_fi->length;
                    g_ptr_array_add(data.ranges,range);

                    last_start = range_fi->start;

                    dbg_print(dbg_pdu,3,dbg_facility,"new_pdu: payload(%i) range %i-%i",hfid,range->start,range->end);
                } else {
                    /* we missed a range  */
                    dbg_print(dbg_pdu,5,dbg_facility,"new_pdu: payload(%i) missed",hfid);
                }

            }
        }
    }

    g_hash_table_foreach(cfg->hfids_attr,get_pdu_fields,&data);

    apply_transforms(pdu->cfg->transforms,pdu->avpl);

    g_ptr_array_free(data.ranges,TRUE);

    return pdu;
}
Example #22
0
DWORD WINAPI  Get_ServerStatusThread2(LPVOID lpParam)
{
    GAME_INFO *pGI = (GAME_INFO *)lpParam;
    SERVER_INFO *pSI=NULL;
    DWORD idx=0;
    DWORD size = pGI->vRefScanSI.size();

    char szScanStatus[256];  //cache local language status text
    strcpy(szScanStatus,g_lang.GetString("ScanStatus"));

    while(pGI->dwScanIdx<size)
    {
        if(SCANNER_bCloseApp)
        {
            dbg_print("Stop scanning SIGNALED!");
            break;
        }

        pSI=NULL;

        EnterCriticalSection(&SCANNER_cs);
        if(pGI->dwScanIdx<size)
        {
            SetStatusText(pGI->iIconIndex,szScanStatus,pGI->dwScanIdx,size);
            pSI = pGI->vRefScanSI.at(pGI->dwScanIdx).pServerInfo; //pGI->vSI.at(pGI->vRefScanSI.at(pGI->dwScanIdx).dwIndex);
            pGI->dwScanIdx++;
        }
        LeaveCriticalSection(&SCANNER_cs);

        //Is there any more server to scan?
        if(pSI==NULL) //if(pSI->usPort==0) //if the port is zero then no equal empty SERVER_INFO structure, (Ugly hack but  it works :))
        {
            //OutputDebugString(">>>>ERROR? Breaked scanning thread\n");
            break;
        }

        //Do non-filtered scan of all servers
        Get_ServerStatus(pSI,NULL,NULL);

        UpdateServerItem(size-pGI->dwScanIdx);

        if(g_hwndProgressBar!=NULL)
            SendMessage(g_hwndProgressBar, PBM_STEPIT, (WPARAM) 0, 0);

        Sleep(AppCFG.dwSleep);
    }

    SetStatusText(pGI->iIconIndex, g_lang.GetString("ScanWaitingForThreads") );

    //This ensures that all threads has been created properly and thread count critical sections works correctly
    //dbg_print("Waiting for all threads to finish the loop!\n");
    DWORD dwWaitResult = WaitForSingleObject(SCAN_hContinueEvent,INFINITE);    // infinite wait
    switch (dwWaitResult)
    {
    // Both event objects were signaled.
    case WAIT_OBJECT_0:
        //	dbg_print("WAIT_OBJECT_0:\n");
        break;
    case WAIT_ABANDONED:
        dbg_print("WAIT_ABANDONED: \n");
        break;
    case WAIT_TIMEOUT:
        dbg_print("WAIT_TIMEOUT:\n");
        break;
    case WAIT_FAILED:
        dbg_print("WAIT_FAILED:\n");
        break;

    // An error occurred.
    default:
        dbg_print("WaitForSingleObject error: \n");
    }

    DWORD id=0;
    //Decrease thread counter....
    EnterCriticalSection( &SCANNER_CSthreadcounter );
    id = SCANNER_dwThreadCounter;
    SCANNER_dwThreadCounter--;
    LeaveCriticalSection( &SCANNER_CSthreadcounter );

//	ExitThread(id);

    return id;
}
kal_bool open_api_h264_add_dpb_info(kal_uint32 frame_addr, kal_uint32 frame_length)
{
    kal_uint32 index;
    kal_bool b_found = KAL_FALSE;
    H264_dpb_frame_entry *p_frame_entry = g_open_api_h264_dpb_frame_info.frame_list;

    dbg_print("[DRV H264]open_api_h264_add_dpb_info(), frame_no:%d\n\r", g_open_api_h264_dec_info_ptr->hdr_add_frames_no);
    video_dbg_trace(H264_DEC_ADD_FRAME, g_open_api_h264_dec_info_ptr->hdr_add_frames_no);

    //Pre Check If the frame_no is exists
    for(index = 0; index < (g_open_api_h264_dpb_frame_info.max_queue_num*2); index++)
    {
        if((p_frame_entry->b_used == KAL_TRUE) && 
           (p_frame_entry->frame_no==g_open_api_h264_dec_info_ptr->hdr_add_frames_no))
        {
            //if previous decode fail is due to dpb full 
            video_dbg_trace(H264_DEC_ADD_EXIST_FRAME,g_open_api_h264_dec_info_ptr->hdr_add_frames_no);
            dbg_print("[DRV H264]open_api_h264_add_dpb_info(), frame_no:%d\n\r", g_open_api_h264_dec_info_ptr->hdr_add_frames_no);
            b_found = KAL_TRUE;
            if(p_frame_entry->p_dpb != 0)
            {
            	video_dbg_trace(H264_DEC_ASSERT,__LINE__);
             VIDEO_ASSERT(0);
            }
             
            p_frame_entry->addr = frame_addr;
            p_frame_entry->length = frame_length;
            
            if(g_open_api_h264_dpb_frame_info.p_next_parse == NULL)
               g_open_api_h264_dpb_frame_info.p_next_parse = p_frame_entry;
            
            return KAL_TRUE;
        }
        
        p_frame_entry++;      
    }
    
    p_frame_entry = g_open_api_h264_dpb_frame_info.frame_list;
    // find empty slot from list
    for(index = 0; index < (g_open_api_h264_dpb_frame_info.max_queue_num*2); index++)
    {
        if(p_frame_entry->b_used == KAL_FALSE)
        {
            b_found = KAL_TRUE;
            break;
        }
        p_frame_entry++;
    }

   
    //if(b_found == KAL_FALSE)
        //EXT_ASSERT(0, g_open_api_h264_dpb_frame_info.max_queue_num, 0, 0);
    
    if(b_found == KAL_FALSE)
    {
    	video_dbg_trace(H264_DEC_DPB_FRAME_ENTRY_FULL,video_get_current_time());
    	dbg_print("[DRV H264]open_api_h264_add_dpb_info()\n\r");
    	return KAL_FALSE;  
    }

    // store the information into the found slot
    p_frame_entry->addr = frame_addr;
    p_frame_entry->length = frame_length;
    p_frame_entry->frame_no=g_open_api_h264_dec_info_ptr->hdr_add_frames_no;
    //p_frame_entry->b_dec_done = KAL_FALSE;
    p_frame_entry->b_used = KAL_TRUE;
    p_frame_entry->p_next_dpb = NULL;
    p_frame_entry->p_prev_dpb = NULL;
    p_frame_entry->p_dpb = NULL;


    //reconstruct the list
    if(g_open_api_h264_dpb_frame_info.p_start == NULL)
    {
        g_open_api_h264_dpb_frame_info.p_start = p_frame_entry;	
        g_open_api_h264_dpb_frame_info.p_end = p_frame_entry;
        g_open_api_h264_dpb_frame_info.p_next_parse = p_frame_entry;
    }
    else
    {
        g_open_api_h264_dpb_frame_info.p_end->p_next_dpb = p_frame_entry;
        p_frame_entry->p_prev_dpb = g_open_api_h264_dpb_frame_info.p_end;
        g_open_api_h264_dpb_frame_info.p_end = p_frame_entry;
        if(g_open_api_h264_dpb_frame_info.p_next_parse == NULL)
            g_open_api_h264_dpb_frame_info.p_next_parse = p_frame_entry;
    }

    return KAL_TRUE;
}
Example #24
0
//Create scanning threads
void Initialize_Rescan2(GAME_INFO *pGI, bool (*filterServerItem)(SERVER_INFO *lp,GAME_INFO *pGI, vFILTER_SETS *vFilterSets))
{
    g_log.AddLogInfo(GS_LOG_DEBUG,"Entering Initialize_Rescan2 function.");
    //SCAN_FilterServerItem = filterServerItem;

    vFILTER_SETS vFS;
    vFS = pGI->vFilterSets;
    vFS.insert(vFS.end(),gm.GetFilterSet(GLOBAL_FILTER).begin(),gm.GetFilterSet(GLOBAL_FILTER).end());
    sort(vFS.begin(),vFS.end(),Sort_Filter_By_GroupName);

    vSRV_INF::iterator  iLst;
    pGI->vRefScanSI.clear();

    pGI->dwViewFlags  |= SCAN_SERVERLIST;

    for ( iLst = pGI->vSI.begin( ); iLst != pGI->vSI.end( ); iLst++ )
    {
        SERVER_INFO *pSI = *iLst;
        REF_SERVER_INFO refSI;
        refSI.pServerInfo = pSI;
        if(filterServerItem!=NULL)
        {
            if(filterServerItem(pSI,pGI,&vFS))
            {
                pGI->vRefScanSI.push_back(refSI);
            }
        }
        else
        {
            pGI->vRefScanSI.push_back(refSI);
        }
    }
    if(pGI->dwViewFlags & SCAN_SERVERLIST)
        pGI->dwViewFlags ^= SCAN_SERVERLIST;

    g_log.AddLogInfo(GS_LOG_INFO,"Preparing to scan %d servers of a total %d.",pGI->vRefScanSI.size(),pGI->vSI.size());

    if(pGI->dwViewFlags & FORCE_SCAN_FILTERED)
        pGI->dwViewFlags = 0;

    if(g_hwndProgressBar!=NULL)
    {
        //Initililze Progressbar
        SendMessage(g_hwndProgressBar, PBM_SETSTEP, (WPARAM) 1, 0);
        SendMessage(g_hwndProgressBar, PBM_SETRANGE, (WPARAM) 0,MAKELPARAM(0,pGI->vRefScanSI.size()));
        SendMessage(g_hwndProgressBar, PBM_SETPOS, (WPARAM) 0, 0);
    }

    HANDLE hThreadIndex[MAX_THREADS];
    DWORD dwThreadId[MAX_THREADS];

    for(DWORD i=0; i<AppCFG.dwThreads; i++)
        hThreadIndex[i]=NULL;

    SCANNER_dwThreadCounter=0;
    pGI->dwScanIdx = 0;

    //Create and setup Continue Event, this is important! Otherwise ETSV can crash.
    SCAN_hContinueEvent = CreateEvent(NULL,TRUE,TRUE,"ScanContinueEvent");
    if (SCAN_hContinueEvent == NULL)
        g_log.AddLogInfo(GS_LOG_DEBUG,"CreateEvent failed (%d)\n", GetLastError());

    if (! ResetEvent(SCAN_hContinueEvent) )
        g_log.AddLogInfo(GS_LOG_DEBUG,"ResetEvent failed (%d)\n", GetLastError());

    DWORD dwMaxThreads = (AppCFG.dwThreads>pGI->vRefScanSI.size())?pGI->vRefScanSI.size():AppCFG.dwThreads;

    //---------------------------------
    //Multi thread scanning code
    //---------------------------------
    //Startup the threads!!!
    for (DWORD i=0; i<dwMaxThreads; i++)
    {
        hThreadIndex[SCANNER_dwThreadCounter] = CreateThread( NULL, 0, &Get_ServerStatusThread2, (LPVOID) pGI ,0, &dwThreadId[SCANNER_dwThreadCounter]);

        if (hThreadIndex[SCANNER_dwThreadCounter] == NULL)
        {
            dbg_print("Error creating thread!\n");
        }
        else
        {
            //g_log.AddLogInfo(GS_LOG_INFO,"Thread created! %d",i);
            EnterCriticalSection( &SCANNER_CSthreadcounter );
            SCANNER_dwThreadCounter++;
            LeaveCriticalSection( &SCANNER_CSthreadcounter );
            //SetThreadName(dwThreadId[SCANNER_dwThreadCounter], "Get_ServerStatusThread2");
        }
    }

    //All threads created in graceful way and counter increased properly
    if (! SetEvent(SCAN_hContinueEvent) )
        dbg_print("SetEvent failed\n");
    //After this this the thread counter can decrease properly with a noncorrupted handle
    DWORD dwStartTick = GetTickCount();
    DWORD iWaitIndex = 0;
    DWORD i=0;
    //Wait for all threads to finish...
    //g_log.AddLogInfo(GS_LOG_DEBUG,"AppCFG.dwThreads %d",AppCFG.dwThreads);

    while(iWaitIndex<dwMaxThreads)
    {

        DWORD max = ((dwMaxThreads-iWaitIndex)<MAXIMUM_WAIT_OBJECTS)?(dwMaxThreads-iWaitIndex):MAXIMUM_WAIT_OBJECTS;

        //	g_log.AddLogInfo(GS_LOG_DEBUG,"iWaitIndex: %d, iWaitIndex+max: %d, dwMaxThreads: %d,  max:%d",iWaitIndex,iWaitIndex+max,dwMaxThreads,max);
        DWORD dwEvent = WaitForMultipleObjects(max, &hThreadIndex[iWaitIndex], TRUE, INFINITE);
        //g_log.AddLogInfo(GS_LOG_DEBUG,">iWaitIndex: %d, iWaitIndex+max: %d, dwMaxThreads: %d, nThreads: %d, max:%d",iWaitIndex,iWaitIndex+max,dwMaxThreads, nThreads,max);

        switch (dwEvent)
        {
        case WAIT_OBJECT_0:
            //dbg_print("First event was signaled.\n");
            break;
        case WAIT_TIMEOUT:
            g_log.AddLogInfo(GS_LOG_DEBUG,"Wait timed out. @ %s",__FUNCTION__);
            break;
        // Return value is invalid.
        default:
        {
            g_log.AddLogInfo(GS_LOG_DEBUG,"Error at waiting threads! %s",__FUNCTION__);
        }
        }


        // Close all thread handles upon completion.
        for(i=iWaitIndex; i<iWaitIndex+max; i++)
        {
            if(hThreadIndex[i]!=NULL)
            {
                CloseHandle(hThreadIndex[i]);
                hThreadIndex[i]=NULL;
            }
        }
        iWaitIndex+=MAXIMUM_WAIT_OBJECTS;
    }
    DWORD dwEndTick = GetTickCount();
    g_log.AddLogInfo(0,"All servers is now scanned...%d sec",(dwEndTick-dwStartTick)/1000);
    pGI->vRefScanSI.clear();
    CloseHandle(SCAN_hContinueEvent);
}
void data_chain_testbench()
{
	int i = 0;
	dbg(char buff[100]);
	struct data_chain chain;
	struct data_chain_node* temp;
	dbg_print("Creating data_chain\n");
	data_chain_init(&chain, BLOCK_SIZE);

	// Prepend test
	dbg_print("Prepending in data_chain\n");
	for(i = 0; i < OP_NB; i++)
	{
		dbg_print1(buff, "Inserting node %d...\t", i);
		data_chain_insert(&chain, NULL, NULL);
		dbg_print("Filling node...");
		data_chain_node_fill(chain.next, BLOCK_SIZE, i);
		dbg_print("Done.\n");
		data_chain_state_print(&chain);
	}
	data_chain_print(&chain);
	
	// Append test 
	dbg_print("Appending in data_chain\n");
	for(i = 0; i < OP_NB; i++)
	{
		dbg_print1(buff, "Inserting node %d...\t", i);
		data_chain_append(&chain, NULL);
		dbg_print("Filling node...");
		data_chain_node_fill(chain.prev, BLOCK_SIZE, i);
		dbg_print("Done.\n");
		data_chain_state_print(&chain);
	}
	data_chain_print(&chain);

	// Insert test
	dbg_print("Inserting in data_chain\n");
	for(i = 0, temp = chain.next; i < OP_NB; i++, temp = temp->next->next)
	{
		dbg_print1(buff, "Inserting node %d...\t", i);
		data_chain_insert(&chain, temp, NULL);
		dbg_print("Filling node...");
		data_chain_node_fill(temp->next, BLOCK_SIZE, i);
		dbg_print("Done.\n");
	}
	data_chain_print(&chain);

	// Deleting ref test
	dbg_print("Deleting in data_chain\n");
	for(i = 0, temp = chain.next; i < OP_NB; i++, temp = temp->next)
	{
		dbg_print1(buff, "Deleting node %d...", i);
		data_chain_del(&chain, temp);
		dbg_print("Done.\n");
	}
	data_chain_print(&chain);

	// Append after ref test
	dbg_print("Reinserting in data_chain\n");
	for(i = 0, temp = chain.next; i < OP_NB; i++, temp = temp->next->next)
	{
		dbg_print1(buff, "Inserting node %d...\t", i);
		data_chain_insert(&chain, temp, NULL);
		dbg_print("Filling node...");
		data_chain_node_fill(temp->next, BLOCK_SIZE, i);
		dbg_print("Done.\n");
	}
	data_chain_print(&chain);
	
	// Freeing chain
	dbg_print("Destroying data_chain...");
	data_chain_destroy(&chain);
	dbg_print("Done.\n");
}
Example #26
0
/**
 * Once we're inside of idleproc_run(), we are executing in the context of the
 * first process-- a real context, so we can finally begin running
 * meaningful code.
 *
 * This is the body of process 0. It should initialize all that we didn't
 * already initialize in kmain(), launch the init process (initproc_run),
 * wait for the init process to exit, then halt the machine.
 *
 * @param arg1 the first argument (unused)
 * @param arg2 the second argument (unused)
 */
static void *
idleproc_run(int arg1, void *arg2)
{
        int status;
        pid_t child;

        /* create init proc */
        kthread_t *initthr = initproc_create();
        init_call_all();
        GDB_CALL_HOOK(initialized);

        /* Create other kernel threads (in order) */
        /* PROCS BLANK {{{ */
#ifdef __SHADOWD__
        /* TODO port this - alvin */
#endif
        /* PROCS BLANK }}} */

#ifdef __VFS__
        /* Once you have VFS remember to set the current working directory
         * of the idle and init processes */
        /* PROCS BLANK {{{ */
        proc_t *idle = proc_lookup(PID_IDLE);
        proc_t *init = proc_lookup(PID_INIT);
        KASSERT(NULL != idle);
        KASSERT(NULL != init);
        idle->p_cwd = vfs_root_vn;
        init->p_cwd = vfs_root_vn;
        vref(vfs_root_vn);
        vref(vfs_root_vn);
        /* PROCS BLANK }}} */

        /* Here you need to make the null, zero, and tty devices using mknod */
        /* You can't do this until you have VFS, check the include/drivers/dev.h
         * file for macros with the device ID's you will need to pass to mknod */
        /* PROCS BLANK {{{ */
        int fd, ii;
        char path[32];

        struct stat statbuf;
        if (do_stat("/dev", &statbuf) < 0) {
                KASSERT(!(status = do_mkdir("/dev")));
        }
        if ((fd = do_open("/dev/null", O_RDONLY)) < 0) {
                KASSERT(!(status = do_mknod("/dev/null", S_IFCHR, MEM_NULL_DEVID)));
        } else {
                do_close(fd);
        }
        if ((fd = do_open("/dev/zero", O_RDONLY)) < 0) {
                KASSERT(!(status = do_mknod("/dev/zero", S_IFCHR, MEM_ZERO_DEVID)));
        } else {
                do_close(fd);
        }

        memset(path, '\0', 32);
        for (ii = 0; ii < __NTERMS__; ii++) {
                sprintf(path, "/dev/tty%d", ii);
                dbg(DBG_INIT, "Creating tty mknod with path %s\n", path);
                if ((fd = do_open(path, O_RDONLY)) < 0) {
                        KASSERT(!do_mknod(path, S_IFCHR, MKDEVID(2, ii)));
                } else {
                        do_close(fd);
                }
        }

        for (ii = 0; ii < __NDISKS__; ii++) {
                sprintf(path, "/dev/hda%d", ii);
                dbg(DBG_INIT, "Creating disk mknod with path %s\n", path);
                if ((fd = do_open(path, O_RDONLY)) < 0) {
                        KASSERT(!do_mknod(path, S_IFBLK, MKDEVID(1, ii)));
                } else {
                        do_close(fd);
                }
        }
        /* PROCS BLANK }}} */
#endif

        /* Finally, enable interrupts (we want to make sure interrupts
         * are enabled AFTER all drivers are initialized) */
        intr_enable();

        /* Run initproc */
        sched_make_runnable(initthr);
        /* Now wait for it */
        child = do_waitpid(-1, 0, &status);
        KASSERT(PID_INIT == child);

#ifdef __MTP__
        kthread_reapd_shutdown();
#endif


#ifdef __SHADOWD__
        /* wait for shadowd to shutdown */
        shadowd_shutdown();
#endif

#ifdef __VFS__
        /* Shutdown the vfs: */
        dbg_print("weenix: vfs shutdown...\n");
        vput(curproc->p_cwd);
        if (vfs_shutdown())
                panic("vfs shutdown FAILED!!\n");

#endif

        /* Shutdown the pframe system */
#ifdef __S5FS__
        pframe_shutdown();
#endif

        dbg_print("\nweenix: halted cleanly!\n");
        GDB_CALL_HOOK(shutdown);
        hard_shutdown();
        return NULL;
}
Example #27
0
/*****************************************************************************
  VCDRead: reads VCD_BLOCKS_ONCE from the VCD and returns that.
  NULL is returned if something went wrong.
 *****************************************************************************/
static block_t *
VCDReadBlock( access_t * p_access )
{
    vcdplayer_t *p_vcdplayer= (vcdplayer_t *)p_access->p_sys;
    const int    i_blocks   = p_vcdplayer->i_blocks_per_read;
    block_t     *p_block;
    int          i_read;
    uint8_t     *p_buf;

    dbg_print( (INPUT_DBG_LSN), "lsn: %lu",
               (long unsigned int) p_vcdplayer->i_lsn );

    /* Allocate a block for the reading */
    if( !( p_block = block_Alloc( i_blocks * M2F2_SECTOR_SIZE ) ) )
    {
        msg_Err( p_access, "cannot get a new block of size: %i",
                 i_blocks * M2F2_SECTOR_SIZE );
        block_Release( p_block );
        return NULL;
    }

    p_buf = (uint8_t *) p_block->p_buffer;
    for ( i_read = 0 ; i_read < i_blocks ; i_read++ )
    {
        vcdplayer_read_status_t read_status = vcdplayer_read(p_access, p_buf);

        switch ( read_status ) {
        case READ_END:
            /* End reached. Return NULL to indicated this. */
            /* We also set the postion to the end so the higher level
               (demux?) doesn't try to keep reading. If everything works out
               right this shouldn't have to happen.
             */
            block_Release( p_block );
            return NULL;

        case READ_ERROR:
            /* Some sort of error. Should we increment lsn? to skip block? */
            block_Release( p_block );
            return NULL;
        case READ_STILL_FRAME:
          /* FIXME The below should be done in an event thread.
             Until then...
           */
#if 1
            msleep( INT64_C(1000) * *p_buf );
            VCDSetOrigin(p_access, p_vcdplayer->origin_lsn,
                         p_vcdplayer->i_track, &(p_vcdplayer->play_item));
            // p_vcd->in_still = false;
            dbg_print(INPUT_DBG_STILL, "still wait time done");
#endif

            block_Release( p_block );
            return NULL;

        default:
        case READ_BLOCK:
            /* Read buffer */
            break;
        }

        p_buf += M2F2_SECTOR_SIZE;
        /* Update seekpoint */
        if ( VCDINFO_ITEM_TYPE_ENTRY == p_vcdplayer->play_item.type )
        {
            size_t i_entry = p_vcdplayer->play_item.num+1;
            lsn_t  i_lsn   = vcdinfo_get_entry_lsn(p_vcdplayer->vcd, i_entry);
            if ( p_vcdplayer->i_lsn >= i_lsn && i_lsn != VCDINFO_NULL_LSN )
            {
                dbg_print( (INPUT_DBG_LSN|INPUT_DBG_PBC),
                           "entry change to %zu, current LSN %u >= end %u",
                           i_entry, p_vcdplayer->i_lsn, i_lsn);

                p_vcdplayer->play_item.num = i_entry;

                VCDSetOrigin( p_access,  i_lsn, p_vcdplayer->i_track,
                              &(p_vcdplayer->play_item) );
            }
        }
    }

    return p_block;
}
Example #28
0
static kal_bool uart_core_task_init(void)
{
	dbg_print("=========>uartcore_task_init\r\n");

	return KAL_TRUE;
}
Example #29
0
/*****************************************************************************
 * VCDParse: parse command line
 *****************************************************************************/
static char *
VCDParse( access_t * p_access, /*out*/ vcdinfo_itemid_t * p_itemid,
          /*out*/ bool *play_single_item )
{
    vcdplayer_t *p_vcdplayer = (vcdplayer_t *)p_access->p_sys;
    char        *psz_parser;
    char        *psz_source;
    char        *psz_next;

    if( var_InheritBool( p_access, MODULE_STRING "-PBC" ) ) {
      p_itemid->type = VCDINFO_ITEM_TYPE_LID;
      p_itemid->num = 1;
      *play_single_item = false;
    }
    else
    {
      p_itemid->type = VCDINFO_ITEM_TYPE_ENTRY;
      p_itemid->num = 0;
    }

#ifdef _WIN32
    /* On Win32 we want the VCD access plugin to be explicitly requested,
     * we end up with lots of problems otherwise */
    if( !p_access->psz_access || !*p_access->psz_access ) return NULL;
#endif

    if( !p_access->psz_location )
    {
        return NULL;
    }

    psz_parser = psz_source = strdup( p_access->psz_location );

    /* Parse input string :
     * [device][@[type][title]] */
    while( *psz_parser && *psz_parser != '@' )
    {
        psz_parser++;
    }

    if( *psz_parser == '@' )
    {
      /* Found the divide between the source name and the
         type+entry number. */
      unsigned int num;

        *psz_parser = '\0';
        ++psz_parser;
        if( *psz_parser )
        switch(*psz_parser) {
        case 'E':
            p_itemid->type = VCDINFO_ITEM_TYPE_ENTRY;
            ++psz_parser;
            *play_single_item = true;
            break;
        case 'P':
            p_itemid->type = VCDINFO_ITEM_TYPE_LID;
            ++psz_parser;
            *play_single_item = false;
            break;
        case 'S':
            p_itemid->type = VCDINFO_ITEM_TYPE_SEGMENT;
            ++psz_parser;
            *play_single_item = true;
            break;
        case 'T':
            p_itemid->type = VCDINFO_ITEM_TYPE_TRACK;
            ++psz_parser;
            *play_single_item = true;
            break;
        default:
            break;
        }

        num = strtol( psz_parser, &psz_next, 10 );
        if ( *psz_parser != '\0' && *psz_next == '\0')
        {
            p_itemid->num = num;
        }

    } else {
        *play_single_item = ( VCDINFO_ITEM_TYPE_LID == p_itemid->type );
    }


    if( !*psz_source )
    {

        /* No source specified, so figure it out. */
        if( !p_access->psz_access ) return NULL;

        psz_source = var_InheritString( p_access, "vcd" );

        if( !psz_source )
        {
            /* Scan for a CD-ROM drive with a VCD in it. */
            char **cd_drives = cdio_get_devices_with_cap(NULL,
                                       (CDIO_FS_ANAL_SVCD|CDIO_FS_ANAL_CVD
                                       |CDIO_FS_ANAL_VIDEOCD|CDIO_FS_UNKNOWN),
                                       true);
            if( NULL == cd_drives ) return NULL;
            if( cd_drives[0] == NULL )
            {
                cdio_free_device_list( cd_drives );
                return NULL;
            }
            psz_source = strdup( cd_drives[0] );
            cdio_free_device_list( cd_drives );
        }
    }

    dbg_print( (INPUT_DBG_CALL|INPUT_DBG_MRL),
               "source=%s entry=%d type=%d",
               psz_source, p_itemid->num, p_itemid->type);

    return psz_source;
}
Example #30
0
/*
   Sets start origin for subsequent seeks/reads
*/
void
VCDSetOrigin( access_t *p_access, lsn_t i_lsn, track_t i_track,
              const vcdinfo_itemid_t *p_itemid )
{
    vcdplayer_t *p_vcdplayer= (vcdplayer_t *)p_access->p_sys;

    dbg_print( (INPUT_DBG_CALL|INPUT_DBG_LSN),
               "i_lsn: %lu, track: %d", (long unsigned int) i_lsn, i_track );

    vcdplayer_set_origin(p_access, i_lsn, i_track, p_itemid);

    switch (p_vcdplayer->play_item.type)
    {
    case VCDINFO_ITEM_TYPE_ENTRY:
        VCDUpdateVar( p_access, p_itemid->num, VLC_VAR_SETVALUE,
                      "chapter", _("Entry"), "Setting entry/segment");
        p_vcdplayer->i_cur_title = i_track - 1;
        if (p_vcdplayer->b_track_length)
        {
            p_vcdplayer->size = p_vcdplayer->p_title[i_track-1]->i_size;
            p_access->info.i_pos  = (uint64_t) M2F2_SECTOR_SIZE *
                     (vcdinfo_get_track_lsn(p_vcdplayer->vcd, i_track)-i_lsn);
        } else {
            p_vcdplayer->size = M2F2_SECTOR_SIZE * (int64_t)
                 vcdinfo_get_entry_sect_count(p_vcdplayer->vcd,p_itemid->num);
            p_access->info.i_pos = 0;
        }
        dbg_print( (INPUT_DBG_LSN|INPUT_DBG_PBC), "size: %"PRIu64", pos: %"PRIu64,
                   p_vcdplayer->size, p_access->info.i_pos );
        p_vcdplayer->i_cur_chapter = p_itemid->num;
        break;

    case VCDINFO_ITEM_TYPE_SEGMENT:
        VCDUpdateVar( p_access, p_itemid->num, VLC_VAR_SETVALUE,
                      "chapter", _("Segment"),  "Setting entry/segment");
        /* The last title entry is the for segments (when segments exist
           and they must here. The segment seekpoints are stored after
           the entry seekpoints and (zeroed) lid seekpoints.
        */
        p_vcdplayer->i_cur_title   = p_vcdplayer->i_titles - 1;
        p_vcdplayer->size          = 0; /* No seeking on stills, please. */
        p_access->info.i_pos       = 0;
        p_vcdplayer->i_cur_chapter = p_vcdplayer->i_entries
                                   + p_vcdplayer->i_lids + p_itemid->num;
        break;

    case VCDINFO_ITEM_TYPE_TRACK:
        p_vcdplayer->i_cur_title   = i_track - 1;
        p_vcdplayer->size          = p_vcdplayer->p_title[i_track - 1]->i_size;
        p_access->info.i_pos       = 0;
        p_vcdplayer->i_cur_chapter = vcdinfo_track_get_entry(p_vcdplayer->vcd,
                                                             i_track);
        break;

    default:
        msg_Warn( p_access, "can't set origin for play type %d",
                  p_vcdplayer->play_item.type );
    }

    VCDUpdateTitle( p_access );

}