FFmpeg: Protocol not on whitelist 'file'! - c

I want to read from an RTP stream, but when I specify "test.sdp" to avformat_open_input() I get this message:
[rtp # 03928900] Protocol not on whitelist 'file'!
Failed: cannot open input.
avformat_open_input() fail: Invalid data found when processing input
Normally if I were using ffplay on the console, I would add the option -protocol_whitelist file,udp,rtp and it would work fine.
So I tried this:
AVDictionary *d = NULL;
av_dict_set(&d, "protocol_whitelist", "file, udp, rtp", 0);
ret = avformat_open_input(&inFormatCtx, filename, NULL, &d);
But the same message still pops up. Any ideas?

This is awkward...
avformat_open_input failed because I have white spaces. Removing the whitespaces now work.
av_dict_set(&d, "protocol_whitelist", "file,udp,rtp", 0);

EDIT: This answer works up to some version. You should use the options parameter of avformat_open_input as described in bot1131357's answer
I'm not totally sure about this, but I believe this options go into the AVFormatContext
AVFormatContext* formatContext = avformat_alloc_context();
formatContext->protocol_whitelist = "file,udp,rtp";
if (avformat_open_input(&formatContext, uri.c_str(), NULL, NULL) != 0) {
return EXIT_FAILURE;
}
Take a look at the cvs log of this change:
https://ffmpeg.org/pipermail/ffmpeg-cvslog/2016-March/098694.html

Related

No-op remuxing of .avi file

I want to demux and then mux .avi file without changing anything.
My program is this (redacted for brevity):
AVFormatContext *input_format_context = NULL;
avformat_open_input(
&input_format_context,
input_url,
NULL, // fmt
NULL // options
);
avformat_find_stream_info(input_format_context, NULL);
AVFormatContext *output_format_context = NULL;
avformat_alloc_output_context2(
&output_format_context,
NULL, // oformat
NULL, // format_name
output_url
);
avio_open2(
&output_format_context->pb,
output_url,
AVIO_FLAG_WRITE,
NULL, // int_cb,
NULL // options
);
for (int i = 0; i < input_format_context->nb_streams; i++) {
avformat_new_stream(output_format_context, NULL);
AVStream *input_stream = input_format_context->streams[i];
AVStream *output_stream = output_format_context->streams[i];
AVCodecParameters *params = avcodec_parameters_alloc();
avcodec_parameters_copy(params, input_stream->codecpar);
output_stream->codecpar = params;
}
avformat_write_header(output_format_context, NULL))
AVPacket *input_packet = NULL;
input_packet = av_packet_alloc();
while (!av_read_frame(
input_format_context,
input_packet
)) {
av_write_frame(output_format_context, input_packet);
av_packet_unref(input_packet);
}
av_write_trailer(output_format_context);
Problem:
Output file is created but instead of close to 10 minute video it is a 24-second slide show consisting of around 3 frames.
It seems that the problem is (perhaps not the only one) lack of PTS on the packet.
When I explicitly print it (input_packet->pts) for each packet it is -9223372036854775808. And also the following warning is printed:
[avi # 0x562868c6c000] Timestamps are unset in a packet for stream 0. This is deprecated and will stop working in the future. Fix your code to set the timestamps properly
How do I then "fix my code to set the timestamps properly"?
I just found a solution.
I added this:
output_stream->time_base = input_stream->time_base;
which then, I understand, allows the video player to calculate PTS on the fly.
This does not remove the warning itself, though. I understand that .avi simply does not have PTS, so it's not a bug as such. To get rid of the warning one can manually set PTS on the packets:
input_packet->pts = calculated_ts;
I would think I should be able to also just do:
output_format_context->oformat->flags |= AVFMT_NOTIMESTAMPS;
However, I cannot do that:
error: assignment of member ‘flags’ in read-only object
So, it looks like ffmpeg is requiring PTS even for .avi or there's a bug or I'm still doing something wrong.

play .wav file using c language

I was asked to play .wav files using C language, the compiler I'm using is Devcpp.
I was trying to use the function PlaySound() as below:
PlaySound("C:/Users/wavfiles/13.1.wav", NULL, SND_FILENAME);
If I directly input the directory to the function like this, it is able to successfully play the sound.
However, I want to set the directory as a variable. I create a text file with a list of directory and extract the one that I want, then put it into PlaySound() function. Here is part of my code:
FILE *fw;
char addr[1000]
char schapter[50];
while(fgets(addr, 1000, fw) != NULL) {
if((strstr(addr, schapter)) != NULL) {
printf("\n%s", addr);
PlaySound(addr, NULL, SND_FILENAME);
}
}
In this case, the directory is assigned to addr (addr = "C:/Users/wavfiles/13.1.wav") and then I put addr into PlaySound(), but it doesn't work.
I have been stuck on this problem for a long time and cannot move on.
I would really appreciate it if anyone can give me suggestions or solutions.
Thank you.
The string returned by fgets() contains the terminal newline. You'll need to remove that to get the filename.
An easy way to do this is to use strchr() to locate the newline:
while (fgets(addr, 1000, fw) != NULL) {
char *nl = strchr(addr, '\n');
if (nl) *nl = 0;
…
}

C_Login fails in PKCS11 in C

Simple issue, but i don't know how to unlock USB Token(epass2003) ,I have try to read PKCS 11 but have no idea how to implement C_Login function for execution in c ,when i am using command line tool (Linux)to do that token is working perfectly fine but with c its not working I have used user type as CKU_USER, Can anyone have knowledge about this, please help
you have to check the return values from the PKCS functions to see if there has been any errors. Try this way and see what happen. If the return code from C_login() is CKR_PIN_LOCKED, then it is clear that you should unlock your card.
CK_RV ret;
ret = C_OpenSession(slot, CKF_SERIAL_SESSION, NULL_PTR, NULL_PTR, &session);
if (ret != CKR_OK){
error_message(ret);
return;
}
readPIN("Intro PIN: ", pin, 4);
ret = (f_C_Login)(hSession,CKU_USER, (unsigned char *) pin,strlen(pin));
if (ret != CKR_OK){
closeSessions(slot);
error_message(ret);
return;
}
A token can get locked due to a certain number of failed login (for TrustKey it is 10). There are provider specific utilities to unlock tokens. You could check Feitian site. There is some pointer to this kind of problem in Gooze forum (though not exactly). Your problem looks quite like a token lock problem.

how to get off with the libxml2 error messages

I want to use the libxml2 lib to parse my xml files.
Now, when I have some bad xml file the lib itself is printing large error messages.
below is some sample code
reader = xmlReaderForFile(filename, NULL, 0);
if (reader != NULL) {
ret = xmlTextReaderRead(reader);
while (ret == 1) {
printf("_________________________________\n");
processNode(reader);
ret = xmlTextReaderRead(reader);
printf("_________________________________\n");
}
xmlFreeTextReader(reader);
if (ret != 0) {
fprintf(stderr, "%s : failed to parse\n", filename);
}
}
In above example, if I have bad xml file, I get error like this
my.xml:4: parser error : attributes construct error
include type="text"this is text. this might be excluded in the next occurrence
my.xml:4: parser error : Couldn't find end of Start Tag include
include type="text"this is text. this might be excluded in the next occurrence
my.xml : failed to parse
Instead, I just want to return some error no. and get off with this ugly lib messages.
what do I do ?
The last parameter to xmlReaderForFile(filename, NULL, 0); is a set of option flags. Reading the documentation for these flags, I see there are two options you might want to set: XML_PARSE_NOERROR and XML_PARSE_NOWARNING. Note that I haven't tried any of this, I just Googled libxml2 and xmlReaderForFile.
You will need to or the flags together like this:
reader = xmlReaderForFile(filename, NULL, XML_PARSE_NOERROR | XML_PARSE_NOWARNING);

How do I actually use Authorization Services?

I've been searching and experimenting for nearly four hours now, so I'm gonna just ask straight up:
How can I correctly use the Authorization Services API to show the user a system-level authorization window, the same one you see when you click a lock icon in System Preferences?
From what I can tell, there is no way to do it using Cocoa if you want to do it programmatically, and if your goal is to call an executable that normally needs to be called via sudo (in my case, /usr/bin/pmset) you're up a creek without a paddle.
I challenge you, I implore you: Please, enlighten me.
Thank you. :)
Obviously you should do real error handling and such, but here is an example to get you started.
AuthorizationRef auth = NULL;
OSStatus err;
err = AuthorizationCreate(NULL,
NULL,
kAuthorizationFlagExtendRights|kAuthorizationFlagInteractionAllowed,
&auth);
if( err != errAuthorizationSuccess ) {
fprintf(stderr, "oops: %ld\n", (long int)err);
exit(-1);
}
char *opts[] = { "some", "parameters", "to", "pm", NULL };
err = AuthorizationExecuteWithPrivileges(
auth,
"/usr/bin/pmset",
kAuthorizationFlagDefaults,
opts,
NULL);
AuthorizationFree(auth, kAuthorizationFlagDefaults);
if( err != errAuthorizationSuccess ) {
fprintf(stderr, "oops: %ld\n", (long int)err);
exit(-1);
}
http://cocoawithlove.com/2009/05/invoking-other-processes-in-cocoa.html
http://developer.apple.com/mac/library/samplecode/BetterAuthorizationSample/index.html

Resources