catalinii / minisatip

minisatip is an SATIP server for linux using local DVB-S2, DVB-C, DVB-T or ATSC cards
https://minisatip.org
328 stars 81 forks source link

Question: Best place to process some output packets #719

Open lars18th opened 4 years ago

lars18th commented 4 years ago

Hi,

I want to process/patch/replace some output packets from the original stream. The idea is a simple byte replacement of some packets (in fact, are EIT packets; but it can be anything). So I ask about the best part of the code to do it. My idea is to target the DVB stream.

Any idea? Thank you!

catalinii commented 4 years ago

You can create a CA (like ca.c) and add a _ts function whichh will be called every time a TS packet exists in the adapter buffer: https://github.com/catalinii/minisatip/blob/master/src/ca.c#L3535

lars18th commented 4 years ago

Hi @catalinii ,

I need more help!

I created a new CA (in fact, based on DDCI that seems more simple). However, even I have the module initialized, I don't receive any call to the TS processing function.

Before we continue on this path, one advise: I don't want to process/filter the TS in any sense related to a CA. What I need is to process/filter the TS every time. Even if it will decrypted or not by some CA running in the minisatip process. My objective is to handle some EIT information on-the-fly. So my processing requires to be independent.

So, that's the relevant part of my code:

void userfilter_init()
{
        memset(&userfilter, 0, sizeof(userfilter));
        userfilter.ca_init_dev  = NULL;
        userfilter.ca_close_dev = NULL;
        userfilter.ca_add_pmt   = NULL;
        userfilter.ca_del_pmt   = NULL;
        userfilter.ca_close_ca  = NULL;
        userfilter.ca_ts        = userf_ts;
        userfilter_id = add_ca(&userfilter, 0xFFFFFFFF);
        LOG("Registered USERFILTER %d", userfilter_id);
}

And I see the Registered USERFILTER 0 line in the LOG. However, the function userf_ts() is never called. Futhermore, when activating the log of the CA module, I see CA 1 will handle adapter 1, that doesn't correspond to my userfilter module.

Any idea?

lars18th commented 4 years ago

Hi @catalinii ,

Fixed! I only need to add the corresponding ca_init_dev (), ca_close_dev() and ca_close_ca(). Without them the CA isn't used.

Thank you! I have what I need.

lars18th commented 4 years ago

Hi @catalinii ,

I have completed the skeleton of a new module called userfilter (based on ca/ddci modules). It's quite simple. So, I ask you if you want that I'll create a PR for incorporating this skeleton into minisatip. The idea is to disable this modules in the configuration by default, and enable it with a simple configure --enable-userfilter. The code then will contain somethig like:

int userf_init_dev(adapter *ad)
{
    return TABLES_RESULT_OK;
}

int userf_close_dev(adapter *ad)
{
    return TABLES_RESULT_OK;
}

int userf_close(adapter *a)
{
    return 0;
}

int userf_ts(adapter *ad)
{
    unsigned char *b;
    int rlen = ad->rlen;
    // Put here your filtering code: b[0] is the first byte of the TS packet, and rlen is the total size of all packets in the buffer.
    return 0;
}

void userfilter_init()
{
        memset(&userfilter, 0, sizeof(userfilter));
        userfilter.ca_init_dev  = userf_init_dev;
        userfilter.ca_close_dev = userf_close_dev;
        userfilter.ca_add_pmt   = NULL;
        userfilter.ca_del_pmt   = NULL;
        userfilter.ca_close_ca  = userf_close;
        userfilter.ca_ts        = userf_ts;
        userfilter_id = add_ca(&userfilter, 0xFFFFFFFF);
        LOG("Registered USERFILTER %d", userfilter_id);
}

Please, let me know if you want to merge it or not. Regards.

lars18th commented 3 years ago

Hi @catalinii ,

I want to know your opinion about this enhancement. Let me to explain some key points:

The filtering is done in this way:

With this will be posible (for the user) to "patch" or "replace" some parts of the original TS. For example, he can replace the NIT tables, or inject new EIT information. The only requirement is to provide the TS file with the target packets.

I want to ask you before implementing this and providing a PR, to have your agreement about merging it or not. Please comment on your ideas/opinions. Regards.

catalinii commented 3 years ago

Hey Lars, I think if you create the patch as disabled, I can merge it. What do you need this feature for ?