fclose all; clear all; close all;

nframes = 50;

qps = [22 27 32 37];
%qps = [32 37];
camera = [39 41];
prob = 1-[0.02 0.03 0.05];
%prob2 = [1 6 10]; % Corresponde a porcentagem fixa de erros com rand(1) para 12 pacotes;
%prob2 = [1 3 7]; 

lambda = [9 14 25; 17 23 23; 11 9 11; 12 17 11];

ACK_frame = 4;
w_fileA='Results\weight_cam';
%w_fileA='none';
w = 1024;
h = 768;
raw_size = h*w*nframes*1.5;
y_mod = zeros([length(qps) length(prob)]);
y_nom = zeros([length(qps) length(prob)]);
rate_mod = zeros([length(qps) length(prob)]);
rate_nom = zeros([length(qps) length(prob)]);


dep_orig1 = ['Results\Nopt\depth-cam' num2str(camera(1)) '.yuv']; 
dep_orig2 = ['Results\Nopt\depth-cam' num2str(camera(2)) '.yuv']; 
cor_orig1 = ['Results\Nopt\color-cam' num2str(camera(1)) '.yuv'];
cor_orig2 = ['Results\Nopt\color-cam' num2str(camera(2)) '.yuv'];

rdep_orig1 = ['Results\depth-cam' num2str(camera(1)) '.yuv']; 
rdep_orig2 = ['Results\depth-cam' num2str(camera(2)) '.yuv']; 
rcor_orig1 = ['Results\color-cam' num2str(camera(1)) '.yuv'];
rcor_orig2 = ['Results\color-cam' num2str(camera(2)) '.yuv'];

for nqps = 1:1:length(qps)
    
       dep_nom1 = [dep_orig1(1:end-4) '_QP' num2str(qps(nqps)) '_Nopt.264'];
       dep_nom2 = [dep_orig2(1:end-4) '_QP' num2str(qps(nqps)) '_Nopt.264'];
       cor_nom1 = [cor_orig1(1:end-4) '_QP' num2str(qps(nqps)) '_Nopt.264'];
       cor_nom2 = [cor_orig2(1:end-4) '_QP' num2str(qps(nqps)) '_Nopt.264'];
       
       rdep_out1 = [rdep_orig1(1:end-4) '_QP' num2str(qps(nqps))];
       rdep_out2 = [rdep_orig2(1:end-4) '_QP' num2str(qps(nqps))];
       rcor_out1 = [rcor_orig1(1:end-4) '_QP' num2str(qps(nqps))];
       rcor_out2 = [rcor_orig2(1:end-4) '_QP' num2str(qps(nqps))];
           
       for nprob = 1:1:length(prob)
           
           rdep_out_1 = [rdep_out1 '_RobustoErr' num2str(nprob)];
           rdep_out_2 = [rdep_out2 '_RobustoErr' num2str(nprob)];
           rcor_out_1 = [rcor_out1 '_RobustoErr' num2str(nprob)];
           rcor_out_2 = [rcor_out2 '_RobustoErr' num2str(nprob)];
           
           rdep_out1L = [rdep_out_1 '_L' num2str(lambda(nqps,nprob)) '.264'];
           rdep_out2L = [rdep_out_2 '_L' num2str(lambda(nqps,nprob)) '.264'];
           rcor_out1L = [rcor_out_1 '_L' num2str(lambda(nqps,nprob)) '.264'];
           rcor_out2L = [rcor_out_2 '_L' num2str(lambda(nqps,nprob)) '.264'];
           
           syn_pckErr_yuv = ['Results\Syth_QP' num2str(qps(nqps)) '_RobustoErr' num2str(nprob) '_L' num2str(lambda(nqps,nprob)) '_pckErr' num2str(nprob) '.yuv'];
           syn_nomErr_yuv = ['Results\Nopt\Syth_QP' num2str(qps(nqps)) '_Nopt_pckErr' num2str(nprob) '.yuv'];
           
           y_mod(nqps,nprob) = psnr(syn_pckErr_yuv, 'Results\color-cam40.yuv', w, h, nframes);
           y_nom(nqps,nprob) = psnr(syn_nomErr_yuv, 'Results\color-cam40.yuv', w, h, nframes);
           
           
           arq1 = dir(dep_nom1);arq2 = dir(dep_nom2);arq3 = dir(cor_nom1);arq4 = dir(cor_nom2);
           rate_nom(nqps,nprob) = (arq1.bytes + arq2.bytes + arq3.bytes + arq4.bytes)*(8/(10^6))*(30/nframes);
           
           arq1 = dir(rdep_out1L);arq2 = dir(rdep_out2L);arq3 = dir(rcor_out1L);arq4 = dir(rcor_out2L);
           rate_mod(nqps,nprob) = (arq1.bytes + arq2.bytes + arq3.bytes + arq4.bytes)*(8/(10^6))*(30/nframes);
           
       end
       
end


for nprob = 1:1:length(prob)
    
    figure;
    hold on;
    grid on;
    plot(rate_nom(:,nprob),y_nom(:,nprob),'g');
    plot(rate_mod(:,nprob),y_mod(:,nprob),'k');
    hold off;
    grid off;
end