gint sdp_get_codec_pt(const gchar * sdp, idilia_codec codec) { gint pt = -1; const gchar * codec_str = get_codec_name(codec); gchar * expr_str = g_strdup_printf("a=rtpmap:[0-9]+[ \t]+%s/", codec_str); GRegex *regex = g_regex_new(expr_str, 0, 0, NULL); g_free(expr_str); if (regex != NULL) { GMatchInfo *matchInfo; g_regex_match(regex, sdp, 0, &matchInfo); if (g_match_info_matches(matchInfo)) { gchar *result = g_match_info_fetch(matchInfo, 0); if (result) { gchar * sscanf_str = g_strdup_printf("a=rtpmap:%%d%%*[ \t]%s/", codec_str); sscanf(result, sscanf_str, &pt); g_free(sscanf_str); g_free(result); } } g_regex_unref(regex); } return pt; }
static char* get_locale_encoding(void) { #ifdef MS_WINDOWS char codepage[100]; PyOS_snprintf(codepage, sizeof(codepage), "cp%d", GetACP()); return get_codec_name(codepage); #elif defined(HAVE_LANGINFO_H) && defined(CODESET) char* codeset = nl_langinfo(CODESET); if (!codeset || codeset[0] == '\0') { PyErr_SetString(PyExc_ValueError, "CODESET is not set or empty"); return NULL; } return get_codec_name(codeset); #else PyErr_SetNone(PyExc_NotImplementedError); return NULL; #endif }
static gchar * janus_source_do_codec_negotiation(janus_source_session * session, gchar * orig_sdp) { gchar * sdp = NULL; idilia_codec preferred_codec = janus_source_select_video_codec_by_priority_list(orig_sdp); sdp = sdp_set_video_codec(orig_sdp, preferred_codec); g_free(orig_sdp); for (int stream = 0; stream < JANUS_SOURCE_STREAM_MAX; stream++) { if (stream == JANUS_SOURCE_STREAM_VIDEO) { session->codec[stream] = sdp_get_video_codec(sdp); } else if (stream == JANUS_SOURCE_STREAM_AUDIO) { session->codec[stream] = sdp_get_audio_codec(sdp); } session->codec_pt[stream] = sdp_get_codec_pt(sdp, session->codec[stream]); JANUS_LOG(LOG_INFO, "Codec used: %s\n", get_codec_name(session->codec[stream])); } return sdp; }
std::string lavf_get_stream_description(AVStream *pStream) { AVCodecContext *enc = pStream->codec; std::string codec_name = get_codec_name(enc); const char *lang = get_stream_language(pStream); std::string sLanguage; if(lang) { sLanguage = ProbeLangForLanguage(lang); if (sLanguage.empty()) { sLanguage = lang; } } char *title = nullptr; if (AVDictionaryEntry *dictEntry = av_dict_get(pStream->metadata, "title", nullptr, 0)) { title = dictEntry->value; } else if (AVDictionaryEntry *dictEntry = av_dict_get(pStream->metadata, "handler_name", nullptr, 0)) { title = dictEntry->value; if (strcmp(title, "GPAC ISO Video Handler") == 0 || strcmp(title, "VideoHandler") == 0|| strcmp(title, "GPAC ISO Audio Handler") == 0 || strcmp(title, "GPAC Streaming Text Handler") == 0) title = nullptr; } // Empty titles are rather useless if (title && strlen(title) == 0) title = nullptr; int bitrate = get_bit_rate(enc); std::ostringstream buf; switch(enc->codec_type) { case AVMEDIA_TYPE_VIDEO: buf << "V: "; // Title/Language if (title && lang) { buf << title << " [" << lang << "] ("; } else if (title) { // Print either title or lang buf << title << " ("; } else if (lang) { buf << sLanguage << " [" << lang << "] ("; } // Codec buf << codec_name; // Pixel Format if (enc->pix_fmt != AV_PIX_FMT_NONE) { buf << ", " << av_get_pix_fmt_name(enc->pix_fmt); } // Dimensions if (enc->width) { buf << ", " << enc->width << "x" << enc->height; } // Bitrate if (bitrate > 0) { buf << ", " << (bitrate / 1000) << " kb/s"; } // Closing tag if (title || lang) { buf << ")"; } buf << format_flags(pStream->disposition); break; case AVMEDIA_TYPE_AUDIO: buf << "A: "; // Title/Language if (title && lang) { buf << title << " [" << lang << "] ("; } else if (title) { // Print either title or lang buf << title << " ("; } else if (lang) { buf << sLanguage << " [" << lang << "] ("; } // Codec buf << codec_name; // Sample Rate if (enc->sample_rate) { buf << ", " << enc->sample_rate << " Hz"; } if (enc->channels) { // Get channel layout char channel[32]; av_get_channel_layout_string(channel, 32, enc->channels, enc->channel_layout); buf << ", " << channel; } // Sample Format if (show_sample_fmt(enc->codec_id) && get_bits_per_sample(enc, true)) { if (enc->sample_fmt == AV_SAMPLE_FMT_FLT || enc->sample_fmt == AV_SAMPLE_FMT_DBL) { buf << ", fp"; } else { buf << ", s"; } buf << get_bits_per_sample(enc, true); } // Bitrate if (bitrate > 0) { buf << ", " << (bitrate / 1000) << " kb/s"; } // Closing tag if (title || lang) { buf << ")"; } // Flags buf << format_flags(pStream->disposition); break; case AVMEDIA_TYPE_SUBTITLE: buf << "S: "; // Title/Language if (title && lang) { buf << title << " [" << lang << "] ("; } else if (title) { // Print either title or lang buf << title << " ("; } else if (lang) { buf << sLanguage << " [" << lang << "] ("; } // Codec buf << codec_name; if (title || lang) { buf << ")"; } // Subtitle flags buf << format_flags(pStream->disposition); break; default: buf << "Unknown: Stream #" << pStream->index; break; } return buf.str(); }
std::string lavf_get_stream_description(const AVStream *pStream) { AVCodecParameters *par = pStream->codecpar; std::string codec_name = get_codec_name(par); const char *lang = get_stream_language(pStream); std::string sLanguage; if(lang) { sLanguage = ProbeLangForLanguage(lang); if (sLanguage.empty()) { sLanguage = lang; } } const char * title = lavf_get_stream_title(pStream); // Empty titles are rather useless if (title && strlen(title) == 0) title = nullptr; int64_t bitrate = get_bit_rate(par); std::ostringstream buf; switch(par->codec_type) { case AVMEDIA_TYPE_VIDEO: buf << "V: "; // Title/Language if (title && lang) { buf << title << " [" << lang << "] ("; } else if (title) { // Print either title or lang buf << title << " ("; } else if (lang) { buf << sLanguage << " [" << lang << "] ("; } // Codec buf << codec_name; // Pixel Format if (const char *pix_fmt = av_get_pix_fmt_name((AVPixelFormat)par->format)) { buf << ", " << pix_fmt; } // Dimensions if (par->width) { buf << ", " << par->width << "x" << par->height; } // Bitrate if (bitrate > 0) { buf << ", " << (bitrate / 1000) << " kb/s"; } if (par->codec_id == AV_CODEC_ID_H264 && par->profile == FF_PROFILE_H264_STEREO_HIGH) { AVDictionaryEntry *entry = av_dict_get(pStream->metadata, "stereo_mode", nullptr, 0); if (entry && strcmp(entry->value, "mvc_lr") == 0) buf << ", lr"; else if (entry && strcmp(entry->value, "mvc_rl") == 0) buf << ", rl"; } // Closing tag if (title || lang) { buf << ")"; } buf << format_flags(pStream->disposition); break; case AVMEDIA_TYPE_AUDIO: buf << "A: "; // Title/Language if (title && lang) { buf << title << " [" << lang << "] ("; } else if (title) { // Print either title or lang buf << title << " ("; } else if (lang) { buf << sLanguage << " [" << lang << "] ("; } // Codec buf << codec_name; // Sample Rate if (par->sample_rate) { buf << ", " << par->sample_rate << " Hz"; } if (par->channels) { // Get channel layout char channel[32]; av_get_channel_layout_string(channel, 32, par->channels, par->channel_layout); buf << ", " << channel; } // Sample Format if (show_sample_fmt(par) && get_bits_per_sample(par, true)) { if (par->format == AV_SAMPLE_FMT_FLT || par->format == AV_SAMPLE_FMT_DBL) { buf << ", fp"; } else { buf << ", s"; } buf << get_bits_per_sample(par, true); } // Bitrate if (bitrate > 0) { buf << ", " << (bitrate / 1000) << " kb/s"; } // Closing tag if (title || lang) { buf << ")"; } // Flags buf << format_flags(pStream->disposition); break; case AVMEDIA_TYPE_SUBTITLE: buf << "S: "; // Title/Language if (title && lang) { buf << title << " [" << lang << "] ("; } else if (title) { // Print either title or lang buf << title << " ("; } else if (lang) { buf << sLanguage << " [" << lang << "] ("; } // Codec buf << codec_name; if (title || lang) { buf << ")"; } // Subtitle flags buf << format_flags(pStream->disposition); break; default: buf << "Unknown: Stream #" << pStream->index; break; } return buf.str(); }