/*
* Copyright (c) 2014 Stefano Sabatini
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
/**
* @file libavformat AVIOContext read callback API usage example
* @example avio_read_callback.c
*
* Make libavformat demuxer access media content through a custom
* AVIOContext read callback.
*/
size_t size;
///< size left in the buffer
};
static int read_packet(
void *opaque, uint8_t *buf,
int buf_size)
{
if (!buf_size)
/* copy internal buffer data to buf */
memcpy(buf, bd->
ptr, buf_size);
return buf_size;
}
int main(
int argc,
char *argv[])
{
size_t buffer_size, avio_ctx_buffer_size = 4096;
if (argc != 2) {
fprintf(stderr, "usage: %s input_file\n"
"API example program to show how to read from a custom buffer "
"accessed through AVIOContext.\n", argv[0]);
return 1;
}
/* slurp file content into buffer */
goto end;
/* fill opaque structure used by the AVIOContext read callback */
goto end;
}
avio_ctx_buffer =
av_malloc(avio_ctx_buffer_size);
if (!avio_ctx_buffer) {
goto end;
}
if (!avio_ctx) {
goto end;
}
fprintf(stderr, "Could not open input\n");
goto end;
}
fprintf(stderr, "Could not find stream information\n");
goto end;
}
end:
/* note: the internal buffer could have changed, and be != avio_ctx_buffer */
if (avio_ctx)
return 1;
}
return 0;
}