diff options
Diffstat (limited to 'rotord/rotor.cpp')
| -rw-r--r-- | rotord/rotor.cpp | 43 |
1 files changed, 26 insertions, 17 deletions
diff --git a/rotord/rotor.cpp b/rotord/rotor.cpp index 07ea2b7..81b0716 100644 --- a/rotord/rotor.cpp +++ b/rotord/rotor.cpp @@ -307,10 +307,12 @@ bool Render_context::load_audio(const string &filename,vector<base_audio_process av_dump_format(avFormat.get(), 0, 0, false); //avformat.h line 1256 + + AVStream* stream = nullptr; for (unsigned int i = 0; i < avFormat->nb_streams; ++i) { if (avFormat->streams[i]->codec->codec_type == AVMEDIA_TYPE_AUDIO) { - // we've found a video stream! + // we've found a stream! stream = avFormat->streams[i]; break; } @@ -332,37 +334,37 @@ bool Render_context::load_audio(const string &filename,vector<base_audio_process // allocating a structure std::shared_ptr<AVCodecContext> audioCodec(avcodec_alloc_context3(codec), [](AVCodecContext* c) { avcodec_close(c); av_free(c); }); - /* extradata??? + // extradata??? // we need to make a copy of videoStream->codec->extradata and give it to the context // make sure that this vector exists as long as the avVideoCodec exists - std::vector codecContextExtraData(stream->codec->extradata, stream->codec->extradata + stream->codec->extradata_size); - audioCodec->extradata = reinterpret_cast(codecContextExtraData.data()); + std::vector<uint8_t> codecContextExtraData; + codecContextExtraData.assign(stream->codec->extradata, stream->codec->extradata + stream->codec->extradata_size); + + audioCodec->extradata = reinterpret_cast<uint8_t*>(codecContextExtraData.data()); audioCodec->extradata_size = codecContextExtraData.size(); // initializing the structure by opening the codec - if (avcodec_open2(avVideoCodec.get(), codec, nullptr) < 0) { + if (avcodec_open2(audioCodec.get(), codec, nullptr) < 0) { cerr <<"Rotor: Could not open codec"<< endl; return false; } - */ - //avcodec.h line 1026 + //avcodec.h line 1026 - Packet packet(avFormat.get()); - if (packet.packet.data == nullptr) { - //done - return true; - } - - cerr << "audio codec context - sample rate: "<< audioCodec->sample_rate <<", channels: "<<audioCodec->channels<<", sample format: "<<audioCodec->sample_fmt<<endl; + Packet packet; + +// decoding code here + //cerr << "audio codec context - sample rate: "<< audioCodec->sample_rate <<", channels: "<<audioCodec->channels<<", sample format: "<<audioCodec->sample_fmt<<endl; + /* suspect why was this in twice 210313 do { packet.reset(avFormat.get()); if (packet.packet.stream_index != stream->index) - continue; // the packet is not about the video stream we want, let's jump again the start of the loop + continue; // the packet is not about the stream we want, let's jump again the start of the loop } while(0); + */ // allocating an AVFrame std::shared_ptr<AVFrame> avFrame(avcodec_alloc_frame(), &av_free); @@ -401,8 +403,15 @@ bool Render_context::load_audio(const string &filename,vector<base_audio_process // sending data to libavcodec int isFrameAvailable = 0; //const auto processedLength = avcodec_decode_video2(avVideoCodec.get(), avFrame.get(), &isFrameAvailable, &packetToSend); + const auto processedLength = avcodec_decode_audio4(audioCodec.get(), avFrame.get(), &isFrameAvailable, &packetToSend); - +/* + unsigned int bitsPerSample = av_get_bytes_per_sample(stream.codecContext->sample_fmt) * CHAR_BIT; // 16 or 32 + unsigned int numberOfChannels = stream.codecContext->channels; // 1 for mono, 2 for stereo, or more + unsigned int numberOfSamplesContainedInTheFrame = stream.frame->nb_samples * stream.codecContext->channels; + unsigned int numberOfSamplesToPlayPerSecond = stream.codecContext->sample_rate; // usually 44100 or 48000 + const void* data = stream.frame->data[0]; + */ if (processedLength < 0) { //av_free_packet(&packet); shouldn't have to because of type safe wrapper @@ -410,7 +419,7 @@ bool Render_context::load_audio(const string &filename,vector<base_audio_process return false; } offsetInData += processedLength; - + /* // processing the image if available if (isFrameAvailable) { |
