void av_get_channel_layout_string(char *buf, int buf_size, int nb_channels, uint64_t channel_layout) { AVBPrint bp; av_bprint_init_for_buffer(&bp, buf, buf_size); av_bprint_channel_layout(&bp, nb_channels, channel_layout); }
int main(void) { AVBPrint b; char buf[256]; struct tm testtime = { .tm_year = 100, .tm_mon = 11, .tm_mday = 20 }; av_bprint_init(&b, 0, -1); bprint_pascal(&b, 5); printf("Short text in unlimited buffer: %u/%u\n", (unsigned)strlen(b.str), b.len); printf("%s\n", b.str); av_bprint_finalize(&b, NULL); av_bprint_init(&b, 0, -1); bprint_pascal(&b, 25); printf("Long text in unlimited buffer: %u/%u\n", (unsigned)strlen(b.str), b.len); av_bprint_finalize(&b, NULL); av_bprint_init(&b, 0, 2048); bprint_pascal(&b, 25); printf("Long text in limited buffer: %u/%u\n", (unsigned)strlen(b.str), b.len); av_bprint_finalize(&b, NULL); av_bprint_init(&b, 0, 1); bprint_pascal(&b, 5); printf("Short text in automatic buffer: %u/%u\n", (unsigned)strlen(b.str), b.len); av_bprint_init(&b, 0, 1); bprint_pascal(&b, 25); printf("Long text in automatic buffer: %u/%u\n", (unsigned)strlen(b.str)/8*8, b.len); /* Note that the size of the automatic buffer is arch-dependent. */ av_bprint_init(&b, 0, 0); bprint_pascal(&b, 25); printf("Long text count only buffer: %u/%u\n", (unsigned)strlen(b.str), b.len); av_bprint_init_for_buffer(&b, buf, sizeof(buf)); bprint_pascal(&b, 25); printf("Long text count only buffer: %u/%u\n", (unsigned)strlen(buf), b.len); av_bprint_init(&b, 0, -1); av_bprint_strftime(&b, "%Y-%m-%d", &testtime); printf("strftime full: %u/%u \"%s\"\n", (unsigned)strlen(buf), b.len, b.str); av_bprint_finalize(&b, NULL); av_bprint_init(&b, 0, 8); av_bprint_strftime(&b, "%Y-%m-%d", &testtime); printf("strftime truncated: %u/%u \"%s\"\n", (unsigned)strlen(buf), b.len, b.str); return 0; }
void PMS_Log(LogLevel level, const char* format, ...) { // Format the mesage. char msg[2048]; char url[4096]; va_list va; AVBPrint dstbuf; if (av_log_level_plex == AV_LOG_QUIET) return; va_start(va, format); vsnprintf(msg, sizeof(msg), format, va); va_end(va); av_bprint_init_for_buffer(&dstbuf, url, sizeof(url)); // Build the URL. av_bprintf(&dstbuf, "http://127.0.0.1:32400/log?level=%d&source=Transcoder&message=", level); av_bprint_escape(&dstbuf, msg, NULL, AV_ESCAPE_MODE_URL, 0); // Issue the request. av_free(PMS_IssueHttpRequest(url, "GET")); }
void plex_report_stream_detail(const AVStream *st) { if ((st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO || st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) && st->codec_info_nb_frames == 0) return; // Unparsed stream; will be skipped in output if (plexContext.progress_url && (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO || st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO || st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE) && !(st->disposition & AV_DISPOSITION_ATTACHED_PIC)) { char url[4096]; AVBPrint dstbuf; AVDictionaryEntry *lang = av_dict_get(st->metadata, "language", NULL, 0); const char *profile = avcodec_profile_name(st->codecpar->codec_id, st->codecpar->profile); av_bprint_init_for_buffer(&dstbuf, url, sizeof(url)); av_bprintf(&dstbuf, "%s/streamDetail?index=%i&id=%i&codec=%s&type=%s", plexContext.progress_url, st->index, st->id, avcodec_get_name(st->codecpar->codec_id), av_get_media_type_string(st->codecpar->codec_type)); if (st->codecpar->bit_rate) av_bprintf(&dstbuf, "&bitrate=%"PRId64, st->codecpar->bit_rate); if (profile) { av_bprintf(&dstbuf, "&profile="); av_bprint_escape(&dstbuf, profile, NULL, AV_ESCAPE_MODE_URL, 0); } if (lang && lang->value && *lang->value) { av_bprintf(&dstbuf, "&language="); av_bprint_escape(&dstbuf, lang->value, NULL, AV_ESCAPE_MODE_URL, 0); } if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { av_bprintf(&dstbuf, "&width=%i&height=%i", st->codecpar->width, st->codecpar->height); av_bprintf(&dstbuf, "&interlaced=%i", (st->codecpar->field_order != AV_FIELD_PROGRESSIVE && st->codecpar->field_order != AV_FIELD_UNKNOWN)); if (st->codecpar->separate_fields) av_bprintf(&dstbuf, "&separateFields=1"); if (st->codecpar->sample_aspect_ratio.num && st->codecpar->sample_aspect_ratio.den) av_bprintf(&dstbuf, "&sar=%d:%d", st->codecpar->sample_aspect_ratio.num, st->codecpar->sample_aspect_ratio.den); if (st->codecpar->level != FF_LEVEL_UNKNOWN) av_bprintf(&dstbuf, "&level=%d", st->codecpar->level); if (st->avg_frame_rate.num && st->avg_frame_rate.den) av_bprintf(&dstbuf, "&frameRate=%.3f", av_q2d(st->avg_frame_rate)); if (st->internal && st->internal->avctx && st->internal->avctx->properties & FF_CODEC_PROPERTY_CLOSED_CAPTIONS) av_bprintf(&dstbuf, "&closedCaptions=1"); } else if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { char layout[256]; char *layoutP = layout; char *l, *r; av_bprintf(&dstbuf, "&channels=%i", st->codecpar->channels); av_get_channel_layout_string(layout, sizeof(layout), st->codecpar->channels, st->codecpar->channel_layout); l = strchr(layout, '('); r = strrchr(layout, ')'); if (l && r && l > layoutP + 8) { layoutP = l + 1; *r = 0; } av_bprintf(&dstbuf, "&layout="); av_bprint_escape(&dstbuf, layout, NULL, AV_ESCAPE_MODE_URL, 0); av_bprintf(&dstbuf, "&sampleRate=%i", st->codecpar->sample_rate); if (st->codecpar->bits_per_raw_sample) av_bprintf(&dstbuf, "&bitDepth=%i", st->codecpar->bits_per_raw_sample); } #define SEND_DISPOSITION(flagname, name) if (st->disposition & AV_DISPOSITION_##flagname) \ av_bprintf(&dstbuf, "&disp_" name "=1"); SEND_DISPOSITION(DEFAULT, "default"); SEND_DISPOSITION(DUB, "dub"); SEND_DISPOSITION(ORIGINAL, "original"); SEND_DISPOSITION(COMMENT, "comment"); SEND_DISPOSITION(LYRICS, "lyrics"); SEND_DISPOSITION(KARAOKE, "karaoke"); SEND_DISPOSITION(FORCED, "forced"); SEND_DISPOSITION(HEARING_IMPAIRED, "hearing_impaired"); SEND_DISPOSITION(VISUAL_IMPAIRED, "visual_impaired"); SEND_DISPOSITION(CLEAN_EFFECTS, "clean_effects"); SEND_DISPOSITION(ATTACHED_PIC, "attached_pic"); SEND_DISPOSITION(TIMED_THUMBNAILS, "timed_thumbnails"); av_free(PMS_IssueHttpRequest(url, "PUT")); } }