You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

764 lines
19KB

  1. /*
  2. * utils for libavcodec
  3. * Copyright (c) 2001 Fabrice Bellard.
  4. *
  5. * This library is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Lesser General Public
  7. * License as published by the Free Software Foundation; either
  8. * version 2 of the License, or (at your option) any later version.
  9. *
  10. * This library is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public
  16. * License along with this library; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. */
  19. /**
  20. * @file utils.c
  21. * utils.
  22. */
  23. #include "avcodec.h"
  24. #include "dsputil.h"
  25. #include "mpegvideo.h"
  26. void *av_mallocz(unsigned int size)
  27. {
  28. void *ptr;
  29. ptr = av_malloc(size);
  30. if (!ptr)
  31. return NULL;
  32. memset(ptr, 0, size);
  33. return ptr;
  34. }
  35. char *av_strdup(const char *s)
  36. {
  37. char *ptr;
  38. int len;
  39. len = strlen(s) + 1;
  40. ptr = av_malloc(len);
  41. if (!ptr)
  42. return NULL;
  43. memcpy(ptr, s, len);
  44. return ptr;
  45. }
  46. /**
  47. * realloc which does nothing if the block is large enough
  48. */
  49. void *av_fast_realloc(void *ptr, unsigned int *size, unsigned int min_size)
  50. {
  51. if(min_size < *size)
  52. return ptr;
  53. *size= min_size + 10*1024;
  54. return av_realloc(ptr, *size);
  55. }
  56. /* allocation of static arrays - do not use for normal allocation */
  57. static unsigned int last_static = 0;
  58. static char*** array_static = NULL;
  59. static const unsigned int grow_static = 64; // ^2
  60. void *__av_mallocz_static(void** location, unsigned int size)
  61. {
  62. unsigned int l = (last_static + grow_static) & ~(grow_static - 1);
  63. void *ptr = av_mallocz(size);
  64. if (!ptr)
  65. return NULL;
  66. if (location)
  67. {
  68. if (l > last_static)
  69. array_static = av_realloc(array_static, l);
  70. array_static[last_static++] = (char**) location;
  71. *location = ptr;
  72. }
  73. return ptr;
  74. }
  75. /* free all static arrays and reset pointers to 0 */
  76. void av_free_static(void)
  77. {
  78. if (array_static)
  79. {
  80. unsigned i;
  81. for (i = 0; i < last_static; i++)
  82. {
  83. av_free(*array_static[i]);
  84. *array_static[i] = NULL;
  85. }
  86. av_free(array_static);
  87. array_static = 0;
  88. }
  89. last_static = 0;
  90. }
  91. /* cannot call it directly because of 'void **' casting is not automatic */
  92. void __av_freep(void **ptr)
  93. {
  94. av_free(*ptr);
  95. *ptr = NULL;
  96. }
  97. /* encoder management */
  98. AVCodec *first_avcodec;
  99. void register_avcodec(AVCodec *format)
  100. {
  101. AVCodec **p;
  102. p = &first_avcodec;
  103. while (*p != NULL) p = &(*p)->next;
  104. *p = format;
  105. format->next = NULL;
  106. }
  107. typedef struct InternalBuffer{
  108. int last_pic_num;
  109. uint8_t *base[4];
  110. uint8_t *data[4];
  111. }InternalBuffer;
  112. #define INTERNAL_BUFFER_SIZE 32
  113. #define ALIGN(x, a) (((x)+(a)-1)&~((a)-1))
  114. void avcodec_align_dimensions(AVCodecContext *s, int *width, int *height){
  115. int w_align= 1;
  116. int h_align= 1;
  117. switch(s->pix_fmt){
  118. case PIX_FMT_YUV420P:
  119. case PIX_FMT_YUV422:
  120. case PIX_FMT_YUV422P:
  121. case PIX_FMT_YUV444P:
  122. case PIX_FMT_GRAY8:
  123. case PIX_FMT_YUVJ420P:
  124. case PIX_FMT_YUVJ422P:
  125. case PIX_FMT_YUVJ444P:
  126. w_align= 16; //FIXME check for non mpeg style codecs and use less alignment
  127. h_align= 16;
  128. break;
  129. case PIX_FMT_YUV411P:
  130. w_align=32;
  131. h_align=8;
  132. break;
  133. case PIX_FMT_YUV410P:
  134. if(s->codec_id == CODEC_ID_SVQ1){
  135. w_align=64;
  136. h_align=64;
  137. }
  138. break;
  139. default:
  140. w_align= 1;
  141. h_align= 1;
  142. break;
  143. }
  144. *width = ALIGN(*width , w_align);
  145. *height= ALIGN(*height, h_align);
  146. }
  147. int avcodec_default_get_buffer(AVCodecContext *s, AVFrame *pic){
  148. int i;
  149. int w= s->width;
  150. int h= s->height;
  151. InternalBuffer *buf;
  152. assert(pic->data[0]==NULL);
  153. assert(INTERNAL_BUFFER_SIZE > s->internal_buffer_count);
  154. if(s->internal_buffer==NULL){
  155. s->internal_buffer= av_mallocz(INTERNAL_BUFFER_SIZE*sizeof(InternalBuffer));
  156. }
  157. #if 0
  158. s->internal_buffer= av_fast_realloc(
  159. s->internal_buffer,
  160. &s->internal_buffer_size,
  161. sizeof(InternalBuffer)*FFMAX(99, s->internal_buffer_count+1)/*FIXME*/
  162. );
  163. #endif
  164. buf= &((InternalBuffer*)s->internal_buffer)[s->internal_buffer_count];
  165. if(buf->base[0]){
  166. pic->age= pic->coded_picture_number - buf->last_pic_num;
  167. buf->last_pic_num= pic->coded_picture_number;
  168. }else{
  169. int h_chroma_shift, v_chroma_shift;
  170. int s_align, pixel_size;
  171. avcodec_get_chroma_sub_sample(s->pix_fmt, &h_chroma_shift, &v_chroma_shift);
  172. switch(s->pix_fmt){
  173. case PIX_FMT_RGB555:
  174. case PIX_FMT_RGB565:
  175. case PIX_FMT_YUV422:
  176. pixel_size=2;
  177. break;
  178. case PIX_FMT_RGB24:
  179. case PIX_FMT_BGR24:
  180. pixel_size=3;
  181. break;
  182. case PIX_FMT_RGBA32:
  183. pixel_size=4;
  184. break;
  185. default:
  186. pixel_size=1;
  187. }
  188. avcodec_align_dimensions(s, &w, &h);
  189. #if defined(ARCH_POWERPC) || defined(HAVE_MMI) //FIXME some cleaner check
  190. s_align= 16;
  191. #else
  192. s_align= 8;
  193. #endif
  194. if(!(s->flags&CODEC_FLAG_EMU_EDGE)){
  195. w+= EDGE_WIDTH*2;
  196. h+= EDGE_WIDTH*2;
  197. }
  198. buf->last_pic_num= -256*256*256*64;
  199. for(i=0; i<3; i++){
  200. const int h_shift= i==0 ? 0 : h_chroma_shift;
  201. const int v_shift= i==0 ? 0 : v_chroma_shift;
  202. pic->linesize[i]= ALIGN(pixel_size*w>>h_shift, s_align);
  203. buf->base[i]= av_mallocz((pic->linesize[i]*h>>v_shift)+16); //FIXME 16
  204. if(buf->base[i]==NULL) return -1;
  205. memset(buf->base[i], 128, pic->linesize[i]*h>>v_shift);
  206. if(s->flags&CODEC_FLAG_EMU_EDGE)
  207. buf->data[i] = buf->base[i];
  208. else
  209. buf->data[i] = buf->base[i] + ALIGN((pic->linesize[i]*EDGE_WIDTH>>v_shift) + (EDGE_WIDTH>>h_shift), s_align);
  210. }
  211. pic->age= 256*256*256*64;
  212. pic->type= FF_BUFFER_TYPE_INTERNAL;
  213. }
  214. for(i=0; i<4; i++){
  215. pic->base[i]= buf->base[i];
  216. pic->data[i]= buf->data[i];
  217. }
  218. s->internal_buffer_count++;
  219. return 0;
  220. }
  221. void avcodec_default_release_buffer(AVCodecContext *s, AVFrame *pic){
  222. int i;
  223. InternalBuffer *buf, *last, temp;
  224. assert(pic->type==FF_BUFFER_TYPE_INTERNAL);
  225. assert(s->internal_buffer_count);
  226. buf = NULL; /* avoids warning */
  227. for(i=0; i<s->internal_buffer_count; i++){ //just 3-5 checks so is not worth to optimize
  228. buf= &((InternalBuffer*)s->internal_buffer)[i];
  229. if(buf->data[0] == pic->data[0])
  230. break;
  231. }
  232. assert(i < s->internal_buffer_count);
  233. s->internal_buffer_count--;
  234. last = &((InternalBuffer*)s->internal_buffer)[s->internal_buffer_count];
  235. temp= *buf;
  236. *buf= *last;
  237. *last= temp;
  238. for(i=0; i<3; i++){
  239. pic->data[i]=NULL;
  240. // pic->base[i]=NULL;
  241. }
  242. //printf("R%X\n", pic->opaque);
  243. }
  244. enum PixelFormat avcodec_default_get_format(struct AVCodecContext *s, enum PixelFormat * fmt){
  245. return fmt[0];
  246. }
  247. void avcodec_get_context_defaults(AVCodecContext *s){
  248. s->bit_rate= 800*1000;
  249. s->bit_rate_tolerance= s->bit_rate*10;
  250. s->qmin= 2;
  251. s->qmax= 31;
  252. s->mb_qmin= 2;
  253. s->mb_qmax= 31;
  254. s->rc_eq= "tex^qComp";
  255. s->qcompress= 0.5;
  256. s->max_qdiff= 3;
  257. s->b_quant_factor=1.25;
  258. s->b_quant_offset=1.25;
  259. s->i_quant_factor=-0.8;
  260. s->i_quant_offset=0.0;
  261. s->error_concealment= 3;
  262. s->error_resilience= 1;
  263. s->workaround_bugs= FF_BUG_AUTODETECT;
  264. s->frame_rate_base= 1;
  265. s->frame_rate = 25;
  266. s->gop_size= 50;
  267. s->me_method= ME_EPZS;
  268. s->get_buffer= avcodec_default_get_buffer;
  269. s->release_buffer= avcodec_default_release_buffer;
  270. s->get_format= avcodec_default_get_format;
  271. s->me_subpel_quality=8;
  272. s->lmin= FF_QP2LAMBDA * s->qmin;
  273. s->lmax= FF_QP2LAMBDA * s->qmax;
  274. s->sample_aspect_ratio= (AVRational){0,1};
  275. s->intra_quant_bias= FF_DEFAULT_QUANT_BIAS;
  276. s->inter_quant_bias= FF_DEFAULT_QUANT_BIAS;
  277. s->palctrl = NULL;
  278. }
  279. /**
  280. * allocates a AVCodecContext and set it to defaults.
  281. * this can be deallocated by simply calling free()
  282. */
  283. AVCodecContext *avcodec_alloc_context(void){
  284. AVCodecContext *avctx= av_mallocz(sizeof(AVCodecContext));
  285. if(avctx==NULL) return NULL;
  286. avcodec_get_context_defaults(avctx);
  287. return avctx;
  288. }
  289. /**
  290. * allocates a AVPFrame and set it to defaults.
  291. * this can be deallocated by simply calling free()
  292. */
  293. AVFrame *avcodec_alloc_frame(void){
  294. AVFrame *pic= av_mallocz(sizeof(AVFrame));
  295. return pic;
  296. }
  297. int avcodec_open(AVCodecContext *avctx, AVCodec *codec)
  298. {
  299. int ret;
  300. if(avctx->codec)
  301. return -1;
  302. avctx->codec = codec;
  303. avctx->codec_id = codec->id;
  304. avctx->frame_number = 0;
  305. if (codec->priv_data_size > 0) {
  306. avctx->priv_data = av_mallocz(codec->priv_data_size);
  307. if (!avctx->priv_data)
  308. return -ENOMEM;
  309. } else {
  310. avctx->priv_data = NULL;
  311. }
  312. ret = avctx->codec->init(avctx);
  313. if (ret < 0) {
  314. av_freep(&avctx->priv_data);
  315. return ret;
  316. }
  317. return 0;
  318. }
  319. int avcodec_encode_audio(AVCodecContext *avctx, uint8_t *buf, int buf_size,
  320. const short *samples)
  321. {
  322. int ret;
  323. ret = avctx->codec->encode(avctx, buf, buf_size, (void *)samples);
  324. avctx->frame_number++;
  325. return ret;
  326. }
  327. int avcodec_encode_video(AVCodecContext *avctx, uint8_t *buf, int buf_size,
  328. const AVFrame *pict)
  329. {
  330. int ret;
  331. ret = avctx->codec->encode(avctx, buf, buf_size, (void *)pict);
  332. emms_c(); //needed to avoid a emms_c() call before every return;
  333. avctx->frame_number++;
  334. return ret;
  335. }
  336. /**
  337. * decode a frame.
  338. * @param buf bitstream buffer, must be FF_INPUT_BUFFER_PADDING_SIZE larger then the actual read bytes
  339. * because some optimized bitstream readers read 32 or 64 bit at once and could read over the end
  340. * @param buf_size the size of the buffer in bytes
  341. * @param got_picture_ptr zero if no frame could be decompressed, Otherwise, it is non zero
  342. * @return -1 if error, otherwise return the number of
  343. * bytes used.
  344. */
  345. int avcodec_decode_video(AVCodecContext *avctx, AVFrame *picture,
  346. int *got_picture_ptr,
  347. uint8_t *buf, int buf_size)
  348. {
  349. int ret;
  350. ret = avctx->codec->decode(avctx, picture, got_picture_ptr,
  351. buf, buf_size);
  352. emms_c(); //needed to avoid a emms_c() call before every return;
  353. if (*got_picture_ptr)
  354. avctx->frame_number++;
  355. return ret;
  356. }
  357. /* decode an audio frame. return -1 if error, otherwise return the
  358. *number of bytes used. If no frame could be decompressed,
  359. *frame_size_ptr is zero. Otherwise, it is the decompressed frame
  360. *size in BYTES. */
  361. int avcodec_decode_audio(AVCodecContext *avctx, int16_t *samples,
  362. int *frame_size_ptr,
  363. uint8_t *buf, int buf_size)
  364. {
  365. int ret;
  366. ret = avctx->codec->decode(avctx, samples, frame_size_ptr,
  367. buf, buf_size);
  368. avctx->frame_number++;
  369. return ret;
  370. }
  371. int avcodec_close(AVCodecContext *avctx)
  372. {
  373. if (avctx->codec->close)
  374. avctx->codec->close(avctx);
  375. av_freep(&avctx->priv_data);
  376. avctx->codec = NULL;
  377. return 0;
  378. }
  379. AVCodec *avcodec_find_encoder(enum CodecID id)
  380. {
  381. AVCodec *p;
  382. p = first_avcodec;
  383. while (p) {
  384. if (p->encode != NULL && p->id == id)
  385. return p;
  386. p = p->next;
  387. }
  388. return NULL;
  389. }
  390. AVCodec *avcodec_find_encoder_by_name(const char *name)
  391. {
  392. AVCodec *p;
  393. p = first_avcodec;
  394. while (p) {
  395. if (p->encode != NULL && strcmp(name,p->name) == 0)
  396. return p;
  397. p = p->next;
  398. }
  399. return NULL;
  400. }
  401. AVCodec *avcodec_find_decoder(enum CodecID id)
  402. {
  403. AVCodec *p;
  404. p = first_avcodec;
  405. while (p) {
  406. if (p->decode != NULL && p->id == id)
  407. return p;
  408. p = p->next;
  409. }
  410. return NULL;
  411. }
  412. AVCodec *avcodec_find_decoder_by_name(const char *name)
  413. {
  414. AVCodec *p;
  415. p = first_avcodec;
  416. while (p) {
  417. if (p->decode != NULL && strcmp(name,p->name) == 0)
  418. return p;
  419. p = p->next;
  420. }
  421. return NULL;
  422. }
  423. AVCodec *avcodec_find(enum CodecID id)
  424. {
  425. AVCodec *p;
  426. p = first_avcodec;
  427. while (p) {
  428. if (p->id == id)
  429. return p;
  430. p = p->next;
  431. }
  432. return NULL;
  433. }
  434. void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode)
  435. {
  436. const char *codec_name;
  437. AVCodec *p;
  438. char buf1[32];
  439. char channels_str[100];
  440. int bitrate;
  441. if (encode)
  442. p = avcodec_find_encoder(enc->codec_id);
  443. else
  444. p = avcodec_find_decoder(enc->codec_id);
  445. if (p) {
  446. codec_name = p->name;
  447. if (!encode && enc->codec_id == CODEC_ID_MP3) {
  448. if (enc->sub_id == 2)
  449. codec_name = "mp2";
  450. else if (enc->sub_id == 1)
  451. codec_name = "mp1";
  452. }
  453. } else if (enc->codec_id == CODEC_ID_MPEG2TS) {
  454. /* fake mpeg2 transport stream codec (currently not
  455. registered) */
  456. codec_name = "mpeg2ts";
  457. } else if (enc->codec_name[0] != '\0') {
  458. codec_name = enc->codec_name;
  459. } else {
  460. /* output avi tags */
  461. if (enc->codec_type == CODEC_TYPE_VIDEO) {
  462. snprintf(buf1, sizeof(buf1), "%c%c%c%c",
  463. enc->codec_tag & 0xff,
  464. (enc->codec_tag >> 8) & 0xff,
  465. (enc->codec_tag >> 16) & 0xff,
  466. (enc->codec_tag >> 24) & 0xff);
  467. } else {
  468. snprintf(buf1, sizeof(buf1), "0x%04x", enc->codec_tag);
  469. }
  470. codec_name = buf1;
  471. }
  472. switch(enc->codec_type) {
  473. case CODEC_TYPE_VIDEO:
  474. snprintf(buf, buf_size,
  475. "Video: %s%s",
  476. codec_name, enc->mb_decision ? " (hq)" : "");
  477. if (enc->codec_id == CODEC_ID_RAWVIDEO) {
  478. snprintf(buf + strlen(buf), buf_size - strlen(buf),
  479. ", %s",
  480. avcodec_get_pix_fmt_name(enc->pix_fmt));
  481. }
  482. if (enc->width) {
  483. snprintf(buf + strlen(buf), buf_size - strlen(buf),
  484. ", %dx%d, %0.2f fps",
  485. enc->width, enc->height,
  486. (float)enc->frame_rate / enc->frame_rate_base);
  487. }
  488. if (encode) {
  489. snprintf(buf + strlen(buf), buf_size - strlen(buf),
  490. ", q=%d-%d", enc->qmin, enc->qmax);
  491. }
  492. bitrate = enc->bit_rate;
  493. break;
  494. case CODEC_TYPE_AUDIO:
  495. snprintf(buf, buf_size,
  496. "Audio: %s",
  497. codec_name);
  498. switch (enc->channels) {
  499. case 1:
  500. strcpy(channels_str, "mono");
  501. break;
  502. case 2:
  503. strcpy(channels_str, "stereo");
  504. break;
  505. case 6:
  506. strcpy(channels_str, "5:1");
  507. break;
  508. default:
  509. sprintf(channels_str, "%d channels", enc->channels);
  510. break;
  511. }
  512. if (enc->sample_rate) {
  513. snprintf(buf + strlen(buf), buf_size - strlen(buf),
  514. ", %d Hz, %s",
  515. enc->sample_rate,
  516. channels_str);
  517. }
  518. /* for PCM codecs, compute bitrate directly */
  519. switch(enc->codec_id) {
  520. case CODEC_ID_PCM_S16LE:
  521. case CODEC_ID_PCM_S16BE:
  522. case CODEC_ID_PCM_U16LE:
  523. case CODEC_ID_PCM_U16BE:
  524. bitrate = enc->sample_rate * enc->channels * 16;
  525. break;
  526. case CODEC_ID_PCM_S8:
  527. case CODEC_ID_PCM_U8:
  528. case CODEC_ID_PCM_ALAW:
  529. case CODEC_ID_PCM_MULAW:
  530. bitrate = enc->sample_rate * enc->channels * 8;
  531. break;
  532. default:
  533. bitrate = enc->bit_rate;
  534. break;
  535. }
  536. break;
  537. case CODEC_TYPE_DATA:
  538. snprintf(buf, buf_size, "Data: %s", codec_name);
  539. bitrate = enc->bit_rate;
  540. break;
  541. default:
  542. av_abort();
  543. }
  544. if (encode) {
  545. if (enc->flags & CODEC_FLAG_PASS1)
  546. snprintf(buf + strlen(buf), buf_size - strlen(buf),
  547. ", pass 1");
  548. if (enc->flags & CODEC_FLAG_PASS2)
  549. snprintf(buf + strlen(buf), buf_size - strlen(buf),
  550. ", pass 2");
  551. }
  552. if (bitrate != 0) {
  553. snprintf(buf + strlen(buf), buf_size - strlen(buf),
  554. ", %d kb/s", bitrate / 1000);
  555. }
  556. }
  557. unsigned avcodec_version( void )
  558. {
  559. return LIBAVCODEC_VERSION_INT;
  560. }
  561. unsigned avcodec_build( void )
  562. {
  563. return LIBAVCODEC_BUILD;
  564. }
  565. /* must be called before any other functions */
  566. void avcodec_init(void)
  567. {
  568. static int inited = 0;
  569. if (inited != 0)
  570. return;
  571. inited = 1;
  572. dsputil_static_init();
  573. }
  574. /**
  575. * Flush buffers, should be called when seeking or when swicthing to a different stream.
  576. */
  577. void avcodec_flush_buffers(AVCodecContext *avctx)
  578. {
  579. if(avctx->codec->flush)
  580. avctx->codec->flush(avctx);
  581. }
  582. void avcodec_default_free_buffers(AVCodecContext *s){
  583. int i, j;
  584. if(s->internal_buffer==NULL) return;
  585. for(i=0; i<INTERNAL_BUFFER_SIZE; i++){
  586. InternalBuffer *buf= &((InternalBuffer*)s->internal_buffer)[i];
  587. for(j=0; j<4; j++){
  588. av_freep(&buf->base[j]);
  589. buf->data[j]= NULL;
  590. }
  591. }
  592. av_freep(&s->internal_buffer);
  593. s->internal_buffer_count=0;
  594. }
  595. char av_get_pict_type_char(int pict_type){
  596. switch(pict_type){
  597. case I_TYPE: return 'I';
  598. case P_TYPE: return 'P';
  599. case B_TYPE: return 'B';
  600. case S_TYPE: return 'S';
  601. case SI_TYPE:return 'i';
  602. case SP_TYPE:return 'p';
  603. default: return '?';
  604. }
  605. }
  606. int av_reduce(int *dst_nom, int *dst_den, int64_t nom, int64_t den, int64_t max){
  607. int exact=1, sign=0;
  608. int64_t gcd;
  609. assert(den != 0);
  610. if(den < 0){
  611. den= -den;
  612. nom= -nom;
  613. }
  614. if(nom < 0){
  615. nom= -nom;
  616. sign= 1;
  617. }
  618. gcd = ff_gcd(nom, den);
  619. nom /= gcd;
  620. den /= gcd;
  621. if(nom > max || den > max){
  622. AVRational a0={0,1}, a1={1,0};
  623. exact=0;
  624. for(;;){
  625. int64_t x= nom / den;
  626. int64_t a2n= x*a1.num + a0.num;
  627. int64_t a2d= x*a1.den + a0.den;
  628. if(a2n > max || a2d > max) break;
  629. nom %= den;
  630. a0= a1;
  631. a1= (AVRational){a2n, a2d};
  632. if(nom==0) break;
  633. x= nom; nom=den; den=x;
  634. }
  635. nom= a1.num;
  636. den= a1.den;
  637. }
  638. assert(ff_gcd(nom, den) == 1);
  639. if(sign) nom= -nom;
  640. *dst_nom = nom;
  641. *dst_den = den;
  642. return exact;
  643. }
  644. int64_t av_rescale(int64_t a, int b, int c){
  645. uint64_t h, l;
  646. assert(c > 0);
  647. assert(b >=0);
  648. if(a<0) return -av_rescale(-a, b, c);
  649. h= a>>32;
  650. if(h==0) return a*b/c;
  651. l= a&0xFFFFFFFF;
  652. l *= b;
  653. h *= b;
  654. l += (h%c)<<32;
  655. return ((h/c)<<32) + l/c;
  656. }