| 62 | } |
| 63 | |
| 64 | static av_cold int init(AVFormatContext *s) |
| 65 | { |
| 66 | ChromaprintMuxContext *cpr = s->priv_data; |
| 67 | AVStream *st; |
| 68 | |
| 69 | ff_mutex_lock(&chromaprint_mutex); |
| 70 | cpr->ctx = chromaprint_new(cpr->algorithm); |
| 71 | ff_mutex_unlock(&chromaprint_mutex); |
| 72 | |
| 73 | if (!cpr->ctx) { |
| 74 | av_log(s, AV_LOG_ERROR, "Failed to create chromaprint context.\n"); |
| 75 | return AVERROR_EXTERNAL; |
| 76 | } |
| 77 | |
| 78 | if (cpr->silence_threshold != -1) { |
| 79 | #if CPR_VERSION_INT >= AV_VERSION_INT(0, 7, 0) |
| 80 | if (!chromaprint_set_option(cpr->ctx, "silence_threshold", cpr->silence_threshold)) { |
| 81 | av_log(s, AV_LOG_ERROR, "Failed to set silence threshold. Setting silence_threshold requires -algorithm 3 option.\n"); |
| 82 | return AVERROR_EXTERNAL; |
| 83 | } |
| 84 | #else |
| 85 | av_log(s, AV_LOG_ERROR, "Setting the silence threshold requires Chromaprint " |
| 86 | "version 0.7.0 or later.\n"); |
| 87 | return AVERROR(ENOSYS); |
| 88 | #endif |
| 89 | } |
| 90 | |
| 91 | st = s->streams[0]; |
| 92 | |
| 93 | if (st->codecpar->ch_layout.nb_channels > 2) { |
| 94 | av_log(s, AV_LOG_ERROR, "Only up to 2 channels are supported\n"); |
| 95 | return AVERROR(EINVAL); |
| 96 | } |
| 97 | |
| 98 | if (st->codecpar->sample_rate < 1000) { |
| 99 | av_log(s, AV_LOG_ERROR, "Sampling rate must be at least 1000\n"); |
| 100 | return AVERROR(EINVAL); |
| 101 | } |
| 102 | |
| 103 | if (!chromaprint_start(cpr->ctx, st->codecpar->sample_rate, st->codecpar->ch_layout.nb_channels)) { |
| 104 | av_log(s, AV_LOG_ERROR, "Failed to start chromaprint\n"); |
| 105 | return AVERROR_EXTERNAL; |
| 106 | } |
| 107 | |
| 108 | return 0; |
| 109 | } |
| 110 | |
| 111 | static int write_packet(AVFormatContext *s, AVPacket *pkt) |
| 112 | { |
nothing calls this directly
no test coverage detected