156
159
goto out_close_src;
159
dst_fmt->video_codec = CODEC_ID_PNG;
162
dst_fmt->video_codec = CODEC_ID_NONE;
164
/* Try to keep same codec if possible */
165
if ((src->codec_id == CODEC_ID_PNG) && (format & ART_CAN_PNG))
166
dst_fmt->video_codec = CODEC_ID_PNG;
167
else if ((src->codec_id == CODEC_ID_MJPEG) && (format & ART_CAN_JPEG))
168
dst_fmt->video_codec = CODEC_ID_MJPEG;
170
/* If not possible, select new codec */
171
if (dst_fmt->video_codec == CODEC_ID_NONE)
173
if (format & ART_CAN_PNG)
174
dst_fmt->video_codec = CODEC_ID_PNG;
175
else if (format & ART_CAN_JPEG)
176
dst_fmt->video_codec = CODEC_ID_MJPEG;
179
img_encoder = avcodec_find_encoder(dst_fmt->video_codec);
182
DPRINTF(E_LOG, L_ART, "No suitable encoder found for codec ID %d\n", dst_fmt->video_codec);
161
188
dst_ctx = avformat_alloc_context();
197
224
dst->codec_id = dst_fmt->video_codec;
198
225
dst->codec_type = CODEC_TYPE_VIDEO;
199
dst->pix_fmt = PIX_FMT_RGB24;
228
pix_fmts = img_encoder->pix_fmts;
229
while (pix_fmts && (*pix_fmts != -1))
231
pix_fmt_mask |= (1 << *pix_fmts);
235
dst->pix_fmt = avcodec_find_best_pix_fmt(pix_fmt_mask, src->pix_fmt, 1, NULL);
237
if (dst->pix_fmt < 0)
239
DPRINTF(E_LOG, L_ART, "Could not determine best pixel format\n");
245
DPRINTF(E_DBG, L_ART, "Selected pixel format: %d\n", dst->pix_fmt);
201
247
dst->time_base.num = 1;
202
248
dst->time_base.den = 25;
216
262
/* Open encoder */
217
png_encoder = avcodec_find_encoder(dst_fmt->video_codec);
220
DPRINTF(E_LOG, L_ART, "No suitable encoder found for PNG\n");
226
ret = avcodec_open(dst, png_encoder);
263
ret = avcodec_open(dst, img_encoder);
229
266
DPRINTF(E_LOG, L_ART, "Could not open codec for encoding: %s\n", strerror(AVUNERROR(ret)));
496
557
DPRINTF(E_DBG, L_ART, "Destination width %d height %d\n", target_w, target_h);
498
/* Fastpath for PNG */
499
if ((src->codec_id == CODEC_ID_PNG) && !need_rescale)
500
ret = artwork_read(filename, evbuf);
560
if (!need_rescale && format_ok)
562
ret = artwork_read(filename, evbuf);
502
ret = artwork_rescale(src_ctx, s, target_w, target_h, evbuf);
567
ret = artwork_rescale(src_ctx, s, target_w, target_h, format, evbuf);
504
569
av_close_input_file(src_ctx);
558
623
if (i == (sizeof(cover_extension) / sizeof(cover_extension[0])))
561
return artwork_get(artwork, max_w, max_h, evbuf);
626
return artwork_get(artwork, max_w, max_h, format, evbuf);
565
artwork_get_dir_image(char *path, int isdir, int max_w, int max_h, struct evbuffer *evbuf)
630
artwork_get_dir_image(char *path, int isdir, int max_w, int max_h, int format, struct evbuffer *evbuf)
567
632
char artwork[PATH_MAX];
616
681
if (i == (sizeof(cover_basename) / sizeof(cover_basename[0])))
619
return artwork_get(artwork, max_w, max_h, evbuf);
624
artwork_get_item(int id, int max_w, int max_h, struct evbuffer *evbuf)
684
return artwork_get(artwork, max_w, max_h, format, evbuf);
689
artwork_get_item_filename(char *filename, int max_w, int max_h, int format, struct evbuffer *evbuf)
693
/* FUTURE: look at embedded artwork */
695
/* Look for basename(filename).{png,jpg} */
696
ret = artwork_get_own_image(filename, max_w, max_h, format, evbuf);
700
/* Look for basedir(filename)/{artwork,cover}.{png,jpg} */
701
ret = artwork_get_dir_image(filename, 0, max_w, max_h, format, evbuf);
709
artwork_get_item(int id, int max_w, int max_h, int format, struct evbuffer *evbuf)
629
DPRINTF(E_DBG, L_ART, "Artwork request for item %d, max w = %d, max h = %d\n", id, max_w, max_h);
714
DPRINTF(E_DBG, L_ART, "Artwork request for item %d\n", id);
631
716
filename = db_file_path_byid(id);
635
/* FUTURE: look at embedded artwork */
637
/* Look for basename(filename).{png,jpg} */
638
ret = artwork_get_own_image(filename, max_w, max_h, evbuf);
642
/* Look for basedir(filename)/{artwork,cover}.{png,jpg} */
643
ret = artwork_get_dir_image(filename, 0, max_w, max_h, evbuf);
647
DPRINTF(E_DBG, L_ART, "No artwork found for item id %d\n", id);
720
ret = artwork_get_item_filename(filename, max_w, max_h, format, evbuf);
722
DPRINTF(E_DBG, L_ART, "No artwork found for item id %d\n", id);
657
artwork_get_group(int id, int max_w, int max_h, struct evbuffer *evbuf)
730
artwork_get_group(int id, int max_w, int max_h, int format, struct evbuffer *evbuf)
659
732
struct query_params qp;
660
733
struct db_media_file_info dbmfi;
665
DPRINTF(E_DBG, L_ART, "Artwork request for group %d, max w = %d, max h = %d\n", id, max_w, max_h);
738
DPRINTF(E_DBG, L_ART, "Artwork request for group %d\n", id);
667
740
/* Try directory artwork first */
668
741
memset(&qp, 0, sizeof(struct query_params));
683
while ((!got_art) && ((ret = db_query_fetch_string(&qp, &dir)) == 0) && (dir))
756
while ((got_art < 0) && ((ret = db_query_fetch_string(&qp, &dir)) == 0) && (dir))
685
got_art = ! artwork_get_dir_image(dir, 1, max_w, max_h, evbuf);
758
got_art = artwork_get_dir_image(dir, 1, max_w, max_h, format, evbuf);
688
761
db_query_end(&qp);
691
764
DPRINTF(E_LOG, L_ART, "Error fetching Q_GROUP_DIRS results\n");
765
else if (got_art > 0)
696
769
/* Then try individual files */
712
while ((!got_art) && ((ret = db_query_fetch_file(&qp, &dbmfi)) == 0) && (dbmfi.id))
785
while ((got_art < 0) && ((ret = db_query_fetch_file(&qp, &dbmfi)) == 0) && (dbmfi.id))
714
got_art = ! artwork_get_own_image(dbmfi.path, max_w, max_h, evbuf);
787
got_art = artwork_get_own_image(dbmfi.path, max_w, max_h, format, evbuf);
717
790
db_query_end(&qp);
720
793
DPRINTF(E_LOG, L_ART, "Error fetching Q_GROUPITEMS results\n");
794
else if (got_art > 0)