Skip to content

Commit

Permalink
Merge pull request bilibili#5142 from bupt-steven/master
Browse files Browse the repository at this point in the history
fix(init-ios): fix the ffmpeg version in ios/android build scripts
  • Loading branch information
raymond1012 authored Nov 9, 2020
2 parents d35de1b + 0c021a4 commit a71b26b
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 3 deletions.
106 changes: 106 additions & 0 deletions ijkmedia/ijkplayer/ijkavformat/ijklas.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@
#define INIT_BUFFER_THRESHOLD_MAX_MS (8*1000)
#define MAX_BUFFER_TIME 10000
#define MAX_STATE_CNT 30
#define NALU_HEAD_LEN 4
#define H264_NAL_SPS 7
#define H264_NAL_PPS 8

typedef struct AdaptiveConfig {
int32_t buffer_init;
Expand Down Expand Up @@ -1902,6 +1905,105 @@ static void reset_packet(AVPacket* pkt) {
}
}

static bool h264_check_sps_pps(const AVPacket* pkt) {
if (pkt && pkt->data && pkt->size >= 5) {
int offset = 0;

while (offset >= 0 && offset + 5 <= pkt->size) {
uint8_t* nal_start = pkt->data + offset;
int nal_size = AV_RB32(nal_start);
int nal_type = nal_start[4] & 0x1f;

if (nal_type == H264_NAL_SPS || nal_type == H264_NAL_PPS) {
return true;
}

offset += nal_size + 4;
}
}
return false;
}

static bool read_sps_pps_by_avcc(uint8_t* extradata, uint32_t extrasize,
uint8_t** sps, int* sps_len,
uint8_t** pps, int* pps_len) {
uint8_t* spc = extradata + 6;
uint32_t sps_size = AV_RB16(spc);
if (sps_size) {
*sps_len = sps_size;
*sps = (uint8_t*)av_mallocz(sps_size);
if (!*sps) {
return false;
}
spc += 2;
memcpy(*sps, spc, sps_size);
spc += sps_size;
}
spc += 1;
uint32_t pps_size = AV_RB16(spc);
if (pps_size) {
*pps_len = pps_size;
*pps = (uint8_t*)av_mallocz(pps_size);
if (!*pps) {
if (*sps) {
free(*sps);
}
return false;
}
spc += 2;
memcpy(*pps, spc, pps_size);
}
return true;
}

static void insert_sps_pps_into_avpacket(AVPacket* packet, uint8_t* new_extradata, int new_extradata_size, PlayList* playlist) {
uint8_t* sps = NULL, *pps = NULL;
int sps_len = 0, pps_len = 0;

if (read_sps_pps_by_avcc(new_extradata, new_extradata_size, &sps, &sps_len, &pps, &pps_len)) {
int size = packet->size;
if (sps) {
size += NALU_HEAD_LEN + sps_len;
}
if (pps) {
size += NALU_HEAD_LEN + pps_len;
}
if (size == packet->size) {
return;
}
AVPacket new_pack;
int res = av_new_packet(&new_pack, size);
if (res < 0) {
log_error("Failed memory allocation");
} else {
av_packet_copy_props(&new_pack, packet);
uint8_t* data = new_pack.data;

if (sps) {
AV_WB32(data, sps_len);
data += NALU_HEAD_LEN;
memcpy(data, sps, sps_len);
data += sps_len;
log_info("insert sps, size:%d", sps_len);
} else {
log_info("sps is null");
}
if (pps) {
AV_WB32(data, pps_len);
data += NALU_HEAD_LEN;
memcpy(data, pps, pps_len);
data += pps_len;
log_info("insert pps, size:%d", pps_len);
} else {
log_info("pps is null");
}
memcpy(data, packet->data, packet->size);
av_packet_unref(packet);
*packet = new_pack;
}
}
}

static int las_read_packet(AVFormatContext* s, AVPacket* pkt) {
LasContext* c = s->priv_data;
PlayList* playlist = &c->playlist;
Expand Down Expand Up @@ -1936,6 +2038,10 @@ static int las_read_packet(AVFormatContext* s, AVPacket* pkt) {
}
AVCodecParameters* codec = playlist->ctx->streams[pkt->stream_index]->codecpar;
if (codec->extradata) {
if (codec->codec_id == AV_CODEC_ID_H264
&& !h264_check_sps_pps(pkt)) {
insert_sps_pps_into_avpacket(pkt, codec->extradata, codec->extradata_size, playlist);
}
uint8_t *side = av_packet_new_side_data(pkt, AV_PKT_DATA_NEW_EXTRADATA, codec->extradata_size);
if (side) {
memcpy(side, codec->extradata, codec->extradata_size);
Expand Down
2 changes: 1 addition & 1 deletion init-android.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# IJK_FFMPEG_UPSTREAM=git:https://git.videolan.org/ffmpeg.git
IJK_FFMPEG_UPSTREAM=https://github.com/Bilibili/FFmpeg.git
IJK_FFMPEG_FORK=https://github.com/Bilibili/FFmpeg.git
IJK_FFMPEG_COMMIT=ff4.0--git--ijk0.8.8--20201130--001
IJK_FFMPEG_COMMIT=ff4.0--ijk0.8.8--20201130--001
IJK_FFMPEG_LOCAL_REPO=extra/ffmpeg

set -e
Expand Down
2 changes: 1 addition & 1 deletion init-ios.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# IJK_FFMPEG_UPSTREAM=git:https://git.videolan.org/ffmpeg.git
IJK_FFMPEG_UPSTREAM=https://github.com/Bilibili/FFmpeg.git
IJK_FFMPEG_FORK=https://github.com/Bilibili/FFmpeg.git
IJK_FFMPEG_COMMIT=ff4.0--git--ijk0.8.8--20201130--001
IJK_FFMPEG_COMMIT=ff4.0--ijk0.8.8--20201130--001
IJK_FFMPEG_LOCAL_REPO=extra/ffmpeg

IJK_GASP_UPSTREAM=https://github.com/Bilibili/gas-preprocessor.git
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#import "ijkioapplication.h"
#include "string.h"

static const char *kIJKFFRequiredFFmpegVersion = "ff3.4--git--ijk0.8.7--20200911--001";
static const char *kIJKFFRequiredFFmpegVersion = "ff4.0--ijk0.8.8--20201130--001";

// It means you didn't call shutdown if you found this object leaked.
@interface IJKWeakHolder : NSObject
Expand Down

0 comments on commit a71b26b

Please sign in to comment.