Необходимо записать в файл с помощью fopen в классе C++ для проекта iOS

У меня есть проект, в котором используются классы C++ и FFmpeg, мне нужно использовать fopen и записать файл в изолированную программную среду приложения, поэтому код, который мне нужно написать на C++, эквивалентен следующему:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docs_dir = [paths objectAtIndex:0];

Это бы мне в песочницу моего приложения, где я могу в значительной степени манипулировать своими файлами Вопрос в том, как мне написать этот код на С++, чтобы я мог использовать fopen в файле?

Вот метод, который требует реализации:

int testGrabAndWrite(const char* streamURL, bool decode, const char* filename)
{
    FILE *outfile;
    int ret;
    int counter = 0;
    uint8_t *data;              // Pointer to the received audio mem
    int size;                   // Size of the received audio buffer


    outfile = fopen(filename, "w");

    if (outfile == NULL)
        exit(1);

    // Open the RTP stream
    if ((ret = openStream(streamURL, decode)) < 0)
        return ret;

    // Print out info about the stream found
    int tmpSampleRate, tmpBitRate, tmpChannels;
    ret = getStreamInfo(tmpSampleRate, tmpBitRate, tmpChannels);
    printf("\nSample rate:%d Bit rateL%d Channels:%d\n",tmpSampleRate,tmpBitRate, tmpChannels);

    // Grab some sample data and write it to file.
    while (counter < 500) 
    {
        ret = getStreamData(data, size);
        fwrite(data, 1, size, outfile);                             // Write RTP packets, i.e. mp3, to file.
        printf("Wrote packet %d with size %d which returned %d. ", ++counter, size, ret);
    }

    fclose(outfile);
    closeStream();

    return ret;
}
5
задан Benjamin 2 May 2014 в 10:50
поделиться